home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 301-325 / 325 / dclock / dclock-handler.c < prev    next >
C/C++ Source or Header  |  1995-03-14  |  57KB  |  2,003 lines

  1. /* DClock-Handler.c *********************************************************
  2. *
  3. *    DClock-Handler --------    Dumb clock main handler routine,
  4. *                displays clock data and handles
  5. *                DisplayBeep.
  6. *
  7. *    Author ----------------    Olaf 'Olsen' Barthel, MXM
  8. *                Brabeckstrasse 35
  9. *                D-3000 Hannover 71
  10. *
  11. *                Federal Republic of Germany
  12. *
  13. *    This program truly is in the PUBLIC DOMAIN. Written on a cold
  14. *    and damp September evening, hoping the next morning would  be
  15. *    better.
  16. *
  17. *    Compiled using Aztec C 3.6a, CygnusEd Professional 2 & ARexx.
  18. *
  19. ****************************************************************************/
  20.  
  21. #include "DClock.h"
  22.  
  23. #define SIG_CLICK SIGBREAKF_CTRL_C
  24. #define SIG_CLOSE SIGBREAKF_CTRL_D
  25. #define SIG_TIMER SIGBREAKF_CTRL_E
  26. #define SIG_TOGGL SIGBREAKF_CTRL_F
  27. #define SIG_BENCH (1 << BenchSig)
  28. #define SIG_WINDO (1 << Window -> UserPort -> mp_SigBit)
  29.  
  30.     /* Some global data. */
  31.  
  32. struct IntuitionBase    *IntuitionBase;
  33. struct GfxBase        *GfxBase;
  34. struct Window        *Window;
  35. struct RastPort        *RPort;
  36. struct DSeg        *DSeg;
  37. extern struct ExecBase    *SysBase;
  38. ULONG             BenchSig;
  39.  
  40.     /* Our dummy RastPort. */
  41.  
  42. struct BitMap         DummyMap;
  43. struct RastPort         DummyRPort;
  44.  
  45.     /* Default font for clock text. */
  46.  
  47. struct TextAttr DefaultFont =
  48. {
  49.     (UBYTE *)"topaz.font",
  50.     8,
  51.     FS_NORMAL,
  52.     FPF_ROMFONT
  53. };
  54.  
  55.     /* IntuiText to print clock text. */
  56.  
  57. struct IntuiText TimeString =
  58. {
  59.     0,1,
  60.     JAM2,
  61.     0,0,
  62.     (struct TextAttr *)&DefaultFont,
  63.     (UBYTE *)NULL,
  64.     (struct IntuiText *)NULL
  65. };
  66.  
  67. USHORT LeftEdge = 409,TopEdge = 1,Width = 176,Height = 8;
  68.  
  69. struct NewWindow NewWindow =
  70. {
  71.     0,0,
  72.     1,1,
  73.     0,1,
  74.     REFRESHWINDOW,
  75.     BORDERLESS | BACKDROP | BACKDROP | SIMPLE_REFRESH,
  76.     (struct Gadget *)NULL,
  77.     (struct Image *)NULL,
  78.     (STRPTR)NULL,
  79.     (struct Screen *)NULL,
  80.     (struct BitMap *)NULL,
  81.     0,0,
  82.     0,0,
  83.     WBENCHSCREEN
  84. };
  85.  
  86.     /* Some static imagery. */
  87.  
  88. USHORT MapF[16] =
  89. {
  90.     0x0000,0x3FC0,0x3000,0x3FC0,0x3000,0x3000,0x3000,0x0000,
  91.     0xFFF0,0xC030,0xCFF0,0xC030,0xCFF0,0xCFF0,0xCFF0,0xFFF0
  92. };
  93.  
  94. USHORT MapE[16] =
  95. {
  96.     0x0000,0x3FC0,0x3000,0x3FC0,0x3000,0x3000,0x3FC0,0x0000,
  97.     0xFFF0,0xC030,0xCFF0,0xC030,0xCFF0,0xCFF0,0xC030,0xFFF0
  98. };
  99.  
  100. struct Image ImageF =
  101. {
  102.     164,0,
  103.     12,8,2,
  104.     (USHORT *)MapF,
  105.     0x03,0x00,
  106.     (struct Image *)NULL
  107. };
  108.  
  109. struct Image ImageE =
  110. {
  111.     0,0,
  112.     12,8,2,
  113.     (USHORT *)MapE,
  114.     0x03,0x00,
  115.     (struct Image *)&ImageF
  116. };
  117.  
  118.     /* Here comes the click data. */
  119.  
  120. #define LEFT0F  1
  121. #define RIGHT0F  2
  122. #define RIGHT1F  4
  123. #define LEFT1F  8
  124.  
  125. UBYTE AnyChannel[4] =
  126. {
  127.     LEFT0F,
  128.     LEFT1F,
  129.     RIGHT0F,
  130.     RIGHT1F,
  131. };
  132.  
  133.     /* Audio.device control structures. */
  134.  
  135. struct MsgPort        *AudioPort;
  136. struct IOAudio        *Audio;
  137.  
  138.     /* Input.device control structures. */
  139.  
  140. struct MsgPort        *InputDevPort;
  141. struct IOStdReq        *InputRequestBlock;
  142.  
  143.     /* The interrupt handler control. */
  144.  
  145. struct Interrupt     HandlerStuff;
  146.  
  147.     /* Console.device control structures. */
  148.  
  149. long             ConsoleDevice = NULL;
  150. struct IOStdReq         ConStdReq;
  151. struct InputEvent     CopyEvent;
  152.  
  153.     /* This noise was borrowed from Mike Oldfield's
  154.      * "Taurus 2". Sampled with AudioMaster, converted
  155.      * to 'C' sourcecode using a program of mine
  156.      * called "SaveSound".
  157.      */
  158.  
  159. ULONG SoundData[67] =
  160. {
  161.     0xFB0F190A,0xDDB9B4F1,0x377F651E,0xC4B4D323,0x3CEC3274,0x5B0AE2DD,
  162.     0xF105D8E2,0x1937561E,0x00E7DDDD,0xCE9BD3F6,0x0F2D1EEC,0xF1F1D8BE,
  163.     0xAAC4E2FB,0x192D3232,0x05F6DDCE,0xD3F6FB0F,0x234C3C1E,0x0AFBF6DD,
  164.     0xC4DDFB0F,0x1E282319,0x0AFBE2C4,0xD3E2F1F1,0xFB1E370A,0xE7F6F6E2,
  165.     0xC9C9D8FB,0x0FFBFBFB,0x0A05F1C9,0xC9F6F6E7,0xECFB1914,0xF1D8ECFB,
  166.     0xECD8D3DD,0xFB14F1DD,0xECFBF6E2,0xCEC9ECFB,0xE7D8E7FB,0xFBECD3D3,
  167.     0xF1F6E2D3,0xE2F600F6,0xE2E2FBFB,0xECE2E7F1,0xFBFBE7EC,0xFBFBF1EC,
  168.     0xE7F1FBF1,0xE7ECF6F6,0xF1E7ECFB,0xFBFBECE7,0xE7ECECE7,0xF6FBFBF6,
  169.     0xF6F6F6F6,0xF1F6F6F6,0xFBFBFBFB,0xFBFB05FB,0xFBFBFBFB,0xFBFB050A,
  170.     0x0505050A,0x0505FBFB,0xFBFBFBFB,0x0A0A0A05,0x05000505,0x05050505,
  171.     0x05050A0A,0x0A0A0505,0x05050005,0x05050A0A,0x0505050A,0x05050005,
  172.     0x05050505
  173. };
  174.  
  175.     /* Sound run-dump for the ringing alarm clock. Sampled with
  176.      * AudioMaster II, taken from the introduction to "Time"
  177.      * by Pink Floyd (album: "The Dark Side of the Moon").
  178.      */
  179.  
  180. ULONG RingData[1831] =
  181. {
  182.     0xAFA30D00,0x3FDF95D9,0x153D27CD,0xC1E7EFE9,0x3FF9B5DF,0xD73F1DBF,
  183.     0x95B7E12D,0x0DD1E9DB,0xDB4D0BF1,0xE7CF0F37,0x3FE5CFC5,0x17652FF1,
  184.     0xA9E7332D,0x00E1BFE9,0xFF150003,0x93D93F37,0x1FD7B5F1,0x3D17FFB9,
  185.     0xA9EF1D17,0x1FAFDBDF,0xFF1F15DF,0xB5D71F53,0xF9B5D9DF,0x2925CD03,
  186.     0xD7CFF155,0x1FD7BDE1,0x4D4DF7D1,0xBF0BFF0D,0x1FE9E7C7,0x1D1F1FBB,
  187.     0xB7093335,0x1FBDD1FF,0x2D3527E9,0xCB1DEF2F,0x09D7B7D9,0x1F371DE1,
  188.     0xB50B351D,0xD9E909EF,0x2DF129F9,0xB7CB333B,0xF7CFC1DF,0x39EFDDE9,
  189.     0xE1FFFF43,0xF10BCBE7,0x2F27FFDB,0xCFE10D3F,0xD9D1F10D,0x2D071FC1,
  190.     0xFFD9E937,0x29CFD1E7,0x252507AB,0xFD0DCB17,0x000BDFD7,0x07352DD9,
  191.     0xBB00090D,0xE10FD1E9,0x15DD3700,0xAFC5FF17,0x1DF7C1E1,0x27D539E9,
  192.     0xE5F3FF2B,0x0F0DE1DF,0xE9173500,0xE5C9F745,0xE700E5CF,0x05150000,
  193.     0x15ABE74B,0x1721CBC1,0x2D1523C7,0xDDD1EF15,0x0F1FB7D7,0xDBFF27D7,
  194.     0xC5E1E737,0x37F9ADF1,0xDF353BC1,0xE1EBEF00,0x1DE1BBD7,0xE13D43C9,
  195.     0xCFBF2535,0xFFF1C1E7,0xF11D0FF1,0xBFB73541,0x0F039FD3,0x212D2F00,
  196.     0xC5D9452F,0x2FF5B705,0xE7FF2D01,0x0FA71D1B,0x1307E90F,0xE90717FD,
  197.     0xE7B5E123,0x552700D1,0xBDFFEF00,0x0BDF2507,0x5707BFD5,0xC92B3329,
  198.     0xE5D5F1FF,0x1BB9C917,0xFF05D107,0xE1E7CF00,0x45FFBF9D,0xC523F7C7,
  199.     0xD1F11BDF,0x23E1E9CD,0xE7390D1D,0xF7C7E105,0x35E1C9F5,0x0D35E51F,
  200.     0xC1BFD5F3,0x0F17EFC1,0xEF211DD5,0xA5D10DF7,0x1FD900DB,0xCF173735,
  201.     0xEFDFD917,0x11CBD1C1,0xFD4BFF1F,0xE5E7D70D,0xE9130DBF,0xF30F313F,
  202.     0xBFC5133D,0x35DDF9C9,0x0DEF0023,0xDDCFEB27,0x2715B3AB,0xFF3F250D,
  203.     0xC100B73D,0x1FF1E1FF,0xFF1F5103,0xF3BFBB1F,0x4DE3D1C7,0x173529B1,
  204.     0xE1F7EF39,0x0F00C1B7,0xCD1F2703,0xBFD50B3D,0xFFE991BD,0x191D3F00,
  205.     0xD1C7EF07,0x2F11B9C7,0x1B2543CD,0xB1C91D4D,0x2B23E1EB,0xDF193F00,
  206.     0xBFBF0757,0x2507A5C9,0x1D4929E9,0xEDB3FF27,0x00F1BDBF,0x1B4B37E7,
  207.     0xC7A1FF3D,0x1BDDB1F5,0xFF3D0FD5,0xDFDBFF5B,0x43FDA7D1,0xF5613FC1,
  208.     0xE1F53D2F,0x19D1AFEF,0xFF3F47CB,0xC1CD333B,0x3DEBAB1D,0x153D07C1,
  209.     0xA9CF2D2B,0x27E59FFF,0xDF3F1BDB,0xADCD532F,0xEFB1A1EF,0x2D430FFD,
  210.     0xD3AD1D07,0x27C7ABFB,0x3F51E9CF,0xC1BF0D1B,0x2F03AFF9,0xF34FF9BF,
  211.     0xADDB393F,0x19C1B7E9,0xEF510FD1,0x0BFF3B00,0x1FA9CFCD,0xF55901C1,
  212.     0xADEB1F15,0x00E1EF1F,0xFF31E1F1,0x9BDF411F,0x33C1CFF1,0x1DFFFFE3,
  213.     0xB10D45FD,0x0FA5CFFF,0x2317131F,0xA715F92F,0xF9BFDB39,0x41E115FF,
  214.     0xF717CF39,0x00F1E90D,0x13B5C50B,0xFFF7D937,0x0BEF0001,0x00D3FFDB,
  215.     0x3713DBFF,0xEB230BEF,0x03C90017,0x2DE1FF07,0xDD15E1E1,0x21EFD9E1,
  216.     0x1907DFE1,0x074BF3D7,0xC9E11BDF,0xE7071311,0xBFFD0019,0xEBE743DD,
  217.     0x25FDE1E1,0xFFFFFBF5,0x0F0D1DC9,0x13DB0DF5,0xE1070B15,0xD1DF0F1F,
  218.     0xEFC7F113,0xD703C700,0xF1E7F300,0x2FE71DC3,0xE507EBDF,0xDBF117FF,
  219.     0xD9C917FF,0x1DEFE123,0xE7EFABE5,0x07EBDDE9,0x1FFBBF07,0xC31BFFEF,
  220.     0x27F125E1,0xF7D917FF,0xDD3D0F09,0xFFD700F7,0x1500E700,0x0F39D10F,
  221.     0xD911FFE7,0x0017EFE1,0xDFE5F11D,0xDB0033DB,0x1DBFBFF1,0x1BE7D1F9,
  222.     0xD12DEFD5,0xE90DF715,0xEF170DFF,0xBB13DB0F,0xFFEF0F07,0x3500DFE1,
  223.     0x1B1DEFF9,0x0BD71FDF,0xE9070DDB,0x0033001D,0xB9D923FF,0xEFEFDBE9,
  224.     0x15F1E907,0xE90D1DF1,0x2BDFEFB7,0xDF072DE7,0xE10F0F39,0x07C31315,
  225.     0xEF15E10F,0xDFEFE93F,0x13E519E9,0x1713FFE1,0xE7EB1519,0xE9D523D5,
  226.     0x27D31F1F,0xFFF7E929,0xE5EFD109,0x2FEBDD07,0xCF07F7FF,0x001BCFEF,
  227.     0x09B50DD5,0xDF001301,0x19F7D1FF,0x17BFE3CF,0x0F31DFE1,0xD92BC9FF,
  228.     0xF9130BD7,0x0D00EF00,0xE7F30005,0x1F17F5D9,0x33DF0DED,0xDF2D19DF,
  229.     0xE129E1CB,0x0F003109,0xB723FF15,0xBBF70013,0xFFE929E1,0xF9F3EF23,
  230.     0xE7EB23DF,0x00D90DC9,0x0FF3193D,0xC1E10FFF,0xD9DFE900,0xFFD1E13F,
  231.     0xC5FFDD1F,0x17F7FFE1,0x29D1FFE7,0xE900EB29,0x23CF0FFF,0x11E1FF0D,
  232.     0xFF27B317,0xF1CFF935,0xFF07F723,0x15FFE527,0xFF271F03,0x00F5FFD9,
  233.     0x350FF1EF,0xD123FDDB,0xF5D1F117,0xFFE1EBFB,0xBFF7AFD9,0x07BFC9E1,
  234.     0x00F9DFC5,0x073DEBF7,0xE1C105D7,0xF10F0DF9,0xEFF900FF,0xDBB9F9C7,
  235.     0x35FFC9D1,0xB70F1FDB,0xE91D1DC9,0x3BDFF9CF,0xBF1F4DEF,0xE1EF00F9,
  236.     0xFFAF1FFB,0xBD29FFE1,0xD9CBE11F,0x0F0035D7,0xE1230D11,0xABC7232D,
  237.     0xE3C1FFE1,0x1FDFF517,0xD7B7EFFF,0x1FCFBFD9,0x45F5193D,0xC5F9EFFF,
  238.     0x2FD7B5FF,0x1DF117E7,0xC90FCD3B,0x37DBE1D7,0x1537D7C9,0x0315D137,
  239.     0x1107EFB7,0x1339DBC1,0xBFE9031D,0xD107FFB5,0x311D0FED,0xBFD107E9,
  240.     0x00EFD1F1,0x1DE729BD,0xA911150F,0x07DFF90D,0xE9073DD3,0xBB15ED3F,
  241.     0xE3B7F115,0x000F2100,0x09EFE54D,0xEDE9EFFB,0x2FFFE7E9,0xFFF12B3D,
  242.     0xE107DFF7,0x2BE7E115,0xFFE92B27,0x001FBB0F,0x37FFF5DF,0xF107FFD1,
  243.     0xF10BD333,0x150003D7,0xEF030D0F,0xFFE3E131,0xEB17E1C7,0x211D0517,
  244.     0xFFF5DFEB,0xF13D05E1,0x3F003BFF,0xCFF1F7F5,0x00150003,0xFFD127EF,
  245.     0xF715E72F,0x15FFD1D7,0xD10029DD,0x0F0BCD0F,0xCFE50BEF,0xD90125D1,
  246.     0x1DBBD913,0xDF1F15EF,0x00FFD1D1,0xFFC3010B,0xF137F7F1,0xE5DF1715,
  247.     0xF7E91DE7,0xE9FFC70F,0xF7D72F19,0x17EDDFC9,0x1DFFDD35,0xD90325DF,
  248.     0xF1E3D701,0xFF00000D,0xB9F1EFF9,0x2BD3E913,0x1500E7C7,0xD9FFD707,
  249.     0x27B900C7,0xF917EFDB,0x010D001D,0xE1D1FFBF,0x1D35D90B,0xD7F500FF,
  250.     0x00F7DF00,0x451F00F9,0xB7271DF7,0x3FF7CB09,0x1B1917B7,0xE1F7FF17,
  251.     0x0FCFB7D7,0x251725E7,0xB7093311,0xFDB5CF0D,0x1D3F1DE1,0xEFEF1F2F,
  252.     0xDFD1BDD1,0x371BCFC1,0xC9ED25EF,0xC9E5BFC7,0x0F2700EF,0xBD074521,
  253.     0xCBA1A90D,0x0DE900E1,0xD7D7011F,0xF7B7BB05,0x4131EFA9,0xD1F7252F,
  254.     0xF1E1E7FF,0x073FF9B3,0xB3F9272D,0xC9B197FF,0x1DDBD1E1,0x9FD91F00,
  255.     0xF1BF9F0B,0x573DF9B7,0xC1232D00,0x00C1EB25,0x0D1FFDA7,0xAFFD1F4B,
  256.     0xE7AFE11D,0x494BD9E1,0xFFFF253F,0xD9DBCFF3,0x434DF9B3,0xCB1F4D0D,
  257.     0xD1C9D71B,0x3D0500D7,0xA7FF4937,0xFFCFB92F,0x3505D3B5,0xE1331D27,
  258.     0xF1B3D7FF,0x001FDF91,0xC5F73325,0xB7A9F3FF,0x3701C9D1,0xDFDF233F,
  259.     0xF5D7AF0B,0x3F1DB1A9,0xCB2F2D07,0xF1F5AF0B,0x152707BF,0xCF2B451F,
  260.     0xE7B3E12B,0x2D3F2FB9,0xFF0D0F1F,0xF5B5D905,0x2F4BF7C1,0xCDFF451D,
  261.     0xC9F1D7F7,0x171FF1FD,0xCFF15F3B,0xE7BDB707,0x39F3E9E1,0xE9FB2D03,
  262.     0x00CFB70D,0x2F3F0DD3,0xC100153F,0xF1C1F92D,0x112FCBB1,0xF7E70747,
  263.     0x25C1BFED,0x372DCDA5,0xEFFD2DF3,0xE9D1B7CB,0x2F4717C7,0xB30037EF,
  264.     0xE1D9CB23,0x1D2117CB,0x9BEF1D1F,0x1BC7C10B,0x1B370BC1,0xE1FF3D3F,
  265.     0x00C1DBE7,0x0F431FE1,0xCFCF473D,0xD9B9C709,0x452FE907,0xC7CB3551,
  266.     0x17DFBBF3,0x4333E1B3,0xC1F93533,0x27B9BBFF,0x1D2F0FAF,0xBFFB0F2F,
  267.     0x1799A9FF,0x2D45EB99,0xBFFFFD1F,0xF9D1B7E7,0x2743F5A5,0xB7DF1F1D,
  268.     0xFDFFC1BF,0x0B03F1E5,0xD5FF130F,0x00CFDFDB,0x152D1FF9,0xE1C7EF09,
  269.     0xED0BF7F3,0x1D0013FB,0xBDE10013,0x3FE7D5E7,0xFF151BB9,0xD9E9F723,
  270.     0x19E7CFDF,0xED2727E9,0xD9ED002F,0xE9C1D9E7,0x113B2B00,0xBFD70F3D,
  271.     0x05FDFFF5,0x0F2D03F1,0xADC92D35,0x1711AFF5,0x190017FF,0xB703293B,
  272.     0x1FAFA1F3,0xFF0037D1,0xF9DBC715,0x33C3C5D7,0x073FEFB9,0xE9BDDD1D,
  273.     0xE700CFAF,0xF11DC1E1,0xBBC12735,0x0723ABC1,0xFFFF07ED,0xBBE119E9,
  274.     0x07EFB9D3,0xFF2937CF,0xB1EFFB1F,0x1BD300FF,0xBF3735E5,0xC7CFE947,
  275.     0xF7B1CDD1,0xF12DFFE1,0xDFB71125,0x00C1BFBF,0x07092307,0xC7B71335,
  276.     0x1FCF9DE9,0x27FB0000,0xABDDEF1F,0x33079DE3,0x291F11CB,0xC1F1251F,
  277.     0x37D1C1CF,0x154727C7,0xE5DF0037,0x15D9D5CF,0x2F5D17E1,0xB7DF1139,
  278.     0xF50FDBD5,0x114D1FD5,0xAFD34549,0x13D5C7CD,0x0D0D27E1,0xC9EF3333,
  279.     0x0FB3A9DB,0x034537E1,0xC1E7FF3F,0x03C5CF19,0x1D3F03C1,0xA9CF1345,
  280.     0x29D1CBF5,0x3115F1C9,0xDBEF3D41,0x27D1AFD7,0x393D00E1,0xBFEF2115,
  281.     0xE1E1B3FF,0x494F00DD,0xAFDF251F,0x0FD9C3E5,0x391FF9AB,0xC3F73D2F,
  282.     0x0FC3D1DF,0x133717CD,0xD90D273D,0xE1B9C9FB,0x194B00E1,0xCDF32343,
  283.     0xFDE5DF05,0x432300C9,0xC5F53927,0x23D3C7EF,0x250317CB,0xD115312B,
  284.     0x15C1BDFF,0x092BFBD1,0xC7FFF51F,0xE9D5CFFF,0x2935F3C9,0xBFDB2117,
  285.     0xF1E5DFDB,0x250BF5D3,0xBFE33B23,0x00DFCBF1,0x151500F9,0xCD2D11F1,
  286.     0xDBF9D725,0xC70DFDDB,0x000FEFC9,0xD5FB0D15,0xF7E1F7FF,0x0F00E1DF,
  287.     0xFFDF1B05,0xEBFFE11F,0x21DFE9C1,0xC91B0DE7,0xF1F5EFFF,0xC1D90BCB,
  288.     0xC1002F0F,0xFFC10725,0xEBD9D1D1,0x19DFD90F,0xFFEBCB03,0x1FFFDBE1,
  289.     0x13000DFF,0xE1E9EB19,0x11F100EF,0xFFE11DDF,0x0BC5D50B,0x2BD7D1CF,
  290.     0x0D17DBC7,0x00EFB5FB,0xE100DDBF,0xF1270FED,0xE7C9F10D,0xF7E1C9D9,
  291.     0x11EF00D9,0xEFE5FFD3,0x0003CFCD,0xE1092FDF,0xC3001D0D,0xDFFFE511,
  292.     0xF7F92300,0xBDDFF900,0x1BE7E10B,0x07FFFFCD,0xF1BF2323,0xF1E9FDFB,
  293.     0xE91D070D,0xD7BF0031,0xC9E1D507,0x1DFFC100,0xFFCBEFE9,0xF1F9CBE1,
  294.     0x2317FDBB,0xD9F10DEF,0x00D1F10D,0xF70000DF,0xFF2D0023,0x25FBCF1F,
  295.     0xDB31EFD1,0x003D1300,0x0B0F19F7,0xEB271DE1,0xDFF9371D,0xF3E92111,
  296.     0x19F7E52D,0xE7DF00F1,0x00FFCB00,0x1F13EF15,0xD11315FB,0xF1E1E1FD,
  297.     0xEFF107FF,0xFFDBE90B,0xFFCFF1F1,0x0F1BD5E1,0x171DCD05,0xF9FFFFD7,
  298.     0xD927DBED,0xEF0B070D,0xE7E9FFE1,0xFFFF0000,0xEBF500D7,0x13FFFBE9,
  299.     0x0DFF23D5,0xC9210DE7,0x03110B19,0xCFE5350D,0xC1FBF933,0xFFD50019,
  300.     0xFFF90D1F,0x13DFE71F,0x0FE10FEF,0x171B0B0B,0x07D9152D,0xF107F1EB,
  301.     0x23FDE92B,0xFFE9EF2D,0x1F15C7D5,0x1DFFF1D9,0x000FFFE9,0x2703E5CF,
  302.     0xFB1F27BD,0xDD05E109,0x09F900EF,0xDF2D03C1,0xD7F7E517,0xDF0BEFC9,
  303.     0xF11D1BE1,0xBBD527FB,0xD1F1FFE9,0x0DDB27FF,0xB7C32523,0xE5D7C107,
  304.     0x03D5030D,0xE1F7F727,0x00D7C51D,0x130709DD,0xEDD9FF3B,0x15E9CDD7,
  305.     0x2100FFE1,0xE100CDEF,0xF701E5EB,0xFF1FE1F7,0xFFF90743,0x050DBBED,
  306.     0x0FFFF1E1,0xE52115F1,0xE9FFD5AF,0x11232BCB,0xE1D9190D,0xCFD30723,
  307.     0xEF001FE1,0xFFE7F327,0xFFEDADF5,0x1325E7D5,0xF10BFF25,0xE10BFFFB,
  308.     0x1F2337FF,0xF5D93B1D,0xEFC9E117,0x33F7E9F5,0xD7DFEBF1,0x0B15A9FD,
  309.     0x0F23EBBF,0xD10BFFFF,0xD1D1D5EF,0xE3001FBD,0xEFBD0303,0xEFB1B9ED,
  310.     0x231DCDC1,0xF1F715E3,0xD9F1DBE7,0xD13507E7,0xAFDD1715,0xEFD1BB13,
  311.     0x19EFD100,0xEDDF11E5,0x0FE7B7F3,0x27270DDF,0xD10F1D03,0xF9E1FF1D,
  312.     0xF73FFDF7,0xDFD70733,0xEFC1D9FD,0x291DC9D9,0xFFD7FBED,0x17F5CFC9,
  313.     0x0F390DBF,0xC3131DF7,0xE1C9DDFF,0xEF131F07,0xAFEF0F27,0x1DCFE12F,
  314.     0x1515F3E1,0xE1FFFF1F,0x33F5FFF5,0x0F33FFDD,0xC5EB3F3D,0x00E1EFFB,
  315.     0x15F3E127,0xDBD5072F,0x17DFB700,0x4B25C5E1,0xD50DFFF9,0x0FF1F9D7,
  316.     0x190FFDC7,0xBFEB1B2D,0x07C1E9EF,0x0D3F00E1,0xEFFFF933,0x11C9D7E1,
  317.     0x254D03E5,0xBB1D25FB,0x0003E7E1,0x0F2F39F9,0xA1FD4919,0x15C9E50B,
  318.     0x15E91F17,0xCBFF1927,0x17CFC1EF,0x1B27FFE5,0xC9FF0D43,0xE5C9FFFF,
  319.     0x1907ED00,0xDFD70753,0x15C7EFDF,0x470DC9E9,0xFFF50D1D,0x17FFD5D3,
  320.     0x3D2FF5EF,0xE713172B,0xEBDBC100,0x4D11F1C9,0x0B27FFF1,0x03FFCDFB,
  321.     0x170F0FA7,0xC92F151F,0xEFDBE119,0xF30D07B5,0xFF1D030F,0xDBD5C7E9,
  322.     0x1F15FFC1,0xC9EF31E3,0xC501F7FF,0x27DF1FED,0xBF0029E1,0x01E12BE5,
  323.     0xEFD1CFFF,0x1D0B13E9,0xF3F7E70B,0x23F5FF13,0x1323BFED,0xE1EFEF09,
  324.     0xDF1331DF,0xC507F11D,0xFFDD0F0B,0xEDB3E9E1,0xFFFFF113,0x05F7EDC1,
  325.     0x00FFF7D1,0x0707FFCF,0xC900FFFF,0xEFE1171B,0xDBE1F10F,0xF705E103,
  326.     0x09BFD5E9,0x13FFDFF1,0x0029FFC7,0xD5F113DF,0xF127CBF5,0xEFD1E515,
  327.     0xC5E10007,0xFFCDA5F7,0xEFFFD9E9,0x00F7D9D1,0x00FDFDCD,0xE12BEFC7,
  328.     0xD5D10FEF,0xD5E91BFF,0xEFFBE103,0xF7DFD917,0x13F7D7E1,0xF1FFEFF1,
  329.     0xD5171DF7,0xE1E9FF0D,0xEBEB0F2B,0xCF000003,0x15CFC927,0x25EFE9E1,
  330.     0xF1FFC7E1,0x2F0711FF,0xCDD9EFDF,0xE5ED001D,0xEFC3F1FD,0x09F7D10F,
  331.     0x29FDD1E9,0xD917EFF5,0x2F3DEBF1,0xDF0FFFE7,0xF1374D17,0xF70007F7,
  332.     0xDF001B27,0x15F70017,0xFFDD0B00,0x2729E307,0x05DFFFDF,0xD9270DE9,
  333.     0x00170BFF,0xBF003915,0xF9D50007,0xDFCD0F1D,0x21FFDD07,0x1DBFD5F9,
  334.     0x0019FFE9,0x1F15D7F7,0xF5E11DFF,0xE907E903,0xDFED001D,0xFFE1E5F1,
  335.     0x0DCFCD07,0x192B00D5,0x0F15DBD1,0x270305EF,0xE11F11CD,0xD90F1719,
  336.     0xFF000FFF,0xDBF5E307,0xFFEF0000,0x0505EFE1,0x2315F707,0xE1072DD7,
  337.     0x001F1D13,0x0D071FFF,0xC1E12713,0x15EF1739,0xFFF3E30D,0x0BFFFF2F,
  338.     0x31E9FBF9,0x0323EFFB,0x23090BFF,0xE3E10DEB,0x07170009,0xF3DD00F5,
  339.     0xF7DFE90F,0x1BF3D1EB,0xDF13E7DD,0x1BFFDFE1,0xDFEDEFD7,0xDB2717EB,
  340.     0xFBC100EF,0xDFE1FDF5,0xF9F7F1F9,0xF7CDFFFD,0x130DD700,0xE9FFF5ED,
  341.     0xF90FFDFF,0x15EB13AF,0xFFDBE10F,0x1FF5D1BF,0x0DEBEFF9,0x1FFF0D0F,
  342.     0x0907CFED,0xE519FBEF,0xD7F137E7,0xCB00D100,0x15FF00FF,0xEFC7EFE1,
  343.     0x00FFEBC1,0x00FFFBC7,0xE91119CF,0xE9D1F1EB,0xDFF10F1D,0xEBCD0007,
  344.     0xFDCFC10F,0xEF29EBE1,0xD9DFE100,0x1F070B0D,0xD127FFDF,0xD7CF0019,
  345.     0xFFD1D9E9,0x13EFCD0F,0xF3E7FBD3,0x00F3AFDD,0x031F15F5,0xA5F9FFDF,
  346.     0xE9D1D9FF,0xF3F1F1F7,0xAFE7EB17,0x0BBFC9D1,0xEF2BE5E1,0x000DFF17,
  347.     0x0FE9FBD7,0xF54B0DE7,0xCFF5133D,0xD9E1070D,0x2519D100,0xBFDFFF00,
  348.     0x0009DB00,0x390DF7BF,0xA70915FB,0x0FD1F1FB,0xDF001FF7,0xDBEFF129,
  349.     0xDFA9C903,0x2733E1E9,0xF9FFDF17,0xF90FFBFB,0x273FF3D1,0xCB00332D,
  350.     0xF7F105EF,0x1DEBE1F9,0xFFFF3F33,0x17F7CBF1,0x331DFBD9,0x0035FF0F,
  351.     0x00F5FFFF,0xF13315C7,0xCFF91735,0xE3E11F15,0x0DDFE5E1,0xFFFB071F,
  352.     0x00D5CDE9,0x1F1DEFDF,0xDD1F1DFF,0xCDF1DF19,0x13F1F9FB,0xDFE91B0F,
  353.     0xFFDFCF03,0x35E3E5D3,0x07211DF1,0x00FBEBFF,0xF907F1DB,0xE1030F17,
  354.     0xDFD7F12B,0x0D11E5D5,0x11FBEF00,0x01F519FD,0x0F27F7BF,0xF3F72F15,
  355.     0xE1F10F09,0xF109E917,0x150D1F21,0xF3EFDF00,0x1715FD00,0x011F2DDB,
  356.     0xF1EBFB11,0x19F11FF7,0xD1F70F00,0x17DFE92D,0xFFF5D1D9,0xE90DEF07,
  357.     0x07F1EDEF,0xE907DFD5,0xF3EB17FF,0xCFC1F5DD,0x1D0DE9FD,0xFBD3F9EB,
  358.     0xE1E7DBF1,0x2519CDE1,0xC30F0DFF,0xF100EF00,0xF7F100E3,0xDB1B2307,
  359.     0x0FBDE1F9,0x11FD05D5,0x0033F900,0xF9D9051D,0x001FFBCD,0xDB2B1307,
  360.     0xFF031D03,0xF100D1CF,0xF1E929D9,0xE7E9130B,0xFFBF0F19,0x070BE1F1,
  361.     0xF9CFF10B,0x0FFFDBE1,0xFB15EBC9,0xD9131DFB,0x07F1DFDF,0xBFE111EB,
  362.     0xCBDD1705,0xEFBB0011,0xFFE5E1E1,0xFDCBDF00,0x1BFFCFE9,0x0717DBBF,
  363.     0xE9E71DFF,0xE1E9E5CF,0xE90000FF,0xFFD9370D,0xEFB3C100,0x2DFF00F3,
  364.     0x0BFFD7C1,0x13E7B7F3,0x001FFBAB,0xC50F1B15,0xFFD107FF,0xE7E9D1E1,
  365.     0xFBEF170F,0xFFCDC7D1,0x1BFFD3F1,0x031943E5,0xE5F7DFDD,0x113713EB,
  366.     0xC9004513,0xF1E12739,0x1D0003F3,0xEFF70527,0x27B5F11F,0x1B1DDFD1,
  367.     0x271D0DEF,0xE1C9EBE7,0x071FF3DF,0xCFDD1FFF,0xDFC9E127,0x25E5E1F9,
  368.     0xF7FFFBE1,0x13DFC7ED,0x2313EFC5,0xF5332DDF,0xE1DD0BFF,0x05070F19,
  369.     0xE7FB0F0B,0xE7DB001B,0x2D15CBE1,0x010D0013,0x00192DE9,0x131BEBDF,
  370.     0xE3173B0D,0xE1D90D0B,0xEFE10FFF,0xF701F119,0x0BCBF123,0x1DFFE7E9,
  371.     0xF5FFCFD5,0x00F5FFFF,0x07070DDF,0xC7071BFF,0xF3E91709,0x0DC9E103,
  372.     0xFFFB0313,0xFDF7D7E5,0x230DDF13,0x1729FFEB,0xC9FFF7DD,0x111717FF,
  373.     0xD1E9FF0D,0xEFE72719,0xFFDBE9E1,0xF9FFE323,0x1FF7EBDF,0xEB0DF7DD,
  374.     0x001FF517,0xE9E9FFFF,0xFD0F19FB,0xFFE1E10B,0xFFEDEB00,0x330DFDE1,
  375.     0xE7FF09F7,0x0F25D9E7,0x07F913EF,0xCB1B2517,0xF3F5E1FB,0xF7001F00,
  376.     0xEFEFF10F,0xEDCFDDD9,0x131DFBC9,0xF1DF1923,0xE3FD09E7,0xF101F1D5,
  377.     0xD5E11F35,0xE5D9C907,0x15F7E51F,0x000D0F00,0x2FC5EBF7,0x2315F7DF,
  378.     0x00E90DFF,0xF5F53911,0x1D0000FF,0xBFF1030F,0x1DFDD500,0x25EFB900,
  379.     0x0F25EFF1,0xE1FBE7CF,0xD90F09DF,0xE50700DF,0xDFDD0F0D,0x0DEDF1F3,
  380.     0xF7E7E500,0x1DF7FBF1,0x0FFFCFE1,0x01451DF5,0xE90BEFDB,0xE10F190D,
  381.     0xDF172BEF,0xC7C50017,0x15D1F503,0xF7D7D1E9,0xF5D7E700,0x07F3BFBB,
  382.     0xD907EBFF,0xC9000DEF,0xC3D1E5FF,0xEFE50019,0xD7A5C900,0x13D7D1F1,
  383.     0x1BFFD5C3,0xF10DEFF5,0x2F0FFFEB,0xD70015EF,0xE3000027,0xFDC100FF,
  384.     0x1D15E907,0x1DEFE1F1,0x1F1DE7D1,0x1F1DFDD3,0xC50F15CF,0xE10701FF,
  385.     0xDFE107FF,0xBFF10F1F,0x11D7C5E9,0xF7EFDFE1,0x0015EFD1,0xE9FF19F7,
  386.     0x002F39F7,0xD3E90F21,0xE7E52713,0xFFEFD900,0x11EFF927,0x1F1BF7DB,
  387.     0x13FFFFF7,0xED1725EF,0xE1F1010D,0xF3E5271D,0xDFD1E117,0x1DEBF12F,
  388.     0x2BFFEBE1,0x07FBCFE5,0x13230BDF,0xD1F10DEF,0xFBF10F25,0xFFD9E1F9,
  389.     0x0DF7F50F,0x29EBCDD5,0x031DE7E1,0x172D09E3,0xD5000DEF,0xED331FFF,
  390.     0xE7E907FF,0xDDDB1327,0x19EFF1F9,0xEFEF0000,0x23FFDF00,0x0F0DFBDB,
  391.     0xF13D25ED,0xE9E3F7FF,0xE1032F0D,0xDDF9170F,0xE7C7003B,0x3103E100,
  392.     0x0BEFFD0F,0x0D0DFF00,0x1F17CFD9,0xF50F3D0D,0xE1F3FFFF,0x0DF1001D,
  393.     0xFF001F17,0xFDD7DD27,0x3D07CDD1,0x0015DBD9,0x00F50D15,0x0F0FEFBF,
  394.     0xE9190F0D,0xEBE10BFF,0xEFDDC9ED,0xFF050F03,0xDFE7D500,0x2BFFDDF5,
  395.     0xF125FFB9,0xD1F7EF07,0x0F00FFD7,0xC5171BFF,0xD3E92F29,0xF5E1E1FD,
  396.     0xFDE7F70F,0xE50FC7FF,0xDDED0F33,0x07E5EBFF,0xD7DDF141,0xFFFF1B17,
  397.     0x1FBFE9E9,0x11DF00F7,0x0F39CDC1,0x03E5CFFF,0x001FE7EF,0xB1F500FF,
  398.     0xF7F5030D,0xFDEDA3E9,0x0DFFE507,0x07F7C9BD,0x1F11FFDD,0x002925D7,
  399.     0xC5E90DC9,0x09130300,0xB7EB000F,0xEFF7FB17,0x25E5E9D9,0xD915EFE9,
  400.     0x27D7E5DB,0xD5F115CD,0xE93527FF,0xB9A1EFFF,0xDB00F900,0xCFD9E119,
  401.     0xB7AFDB0F,0x2DDFBBD1,0xCDD9EFDF,0xE9FFFBE3,0x3BE1FBDB,0xDD002D19,
  402.     0xF5B7E91D,0x0DE1F9DF,0x1515DF0F,0xFFC7E51B,0x2F37EFB1,0x191DFFEB,
  403.     0xCBE9350D,0x13E9D9DB,0xFBFD1F31,0xE7FBCDE1,0x0FD7C1F1,0x094729C5,
  404.     0xD1FFDFFF,0x1BF11DEB,0xE7172DC7,0xCBDF2749,0x1DE500CD,0xFFF7000F,
  405.     0xFFFF2729,0x0FFFBFD1,0x2B2D2117,0xD10F1DE7,0x0005FB15,0x15002FED,
  406.     0xAFC3FD2F,0x2DDF0009,0x19EFD7C9,0x0FFF0943,0x00E1DFCB,0x002BFFFF,
  407.     0xF7F10725,0xC1C1E909,0x451D0300,0x15CFE51F,0x23FFF7F9,0x3F0DF3B7,
  408.     0xF11F3935,0x0F13CD1D,0xF5EB1315,0xFF2F0F13,0x19EFB923,0x3D090FD1,
  409.     0x0011E3E1,0xFF15FFFB,0x1F1FFFB7,0xD1F32F0D,0xD91F13D7,0xD1F3E10D,
  410.     0xEFED2F27,0xB5FFD900,0x190D1327,0x13F1FFD1,0xD9F5FF17,0x0F0F2FDF,
  411.     0xD3D9F715,0x19E92F3D,0xD5DD00EF,0x1DEFE53D,0x15D9C3ED,0xD1EFDF17,
  412.     0x3907EFEB,0xED00BFD7,0x17ED0F0D,0xE3B1E1AF,0x1113C509,0x1DDBC9EB,
  413.     0xD1EBDFE1,0x3B3BC1D7,0xC707EFDF,0xF12505F1,0xFFF1F1BF,0xCF3F3D00,
  414.     0x21C7F1ED,0xDF002FE1,0x0B3D1FF1,0xC7EF0033,0xF1FFFBF5,0x153DE100,
  415.     0xC92500ED,0x0017EF0D,0x250F00DF,0xE1E927FF,0xE1DB1F2D,0xFFB303F1,
  416.     0xE9EFED00,0x47EBCBF9,0x0FF9D7C9,0xE91B1DF7,0xD1E9EFDF,0xD3F1F5FF,
  417.     0xDFE10013,0xD7ADC1FF,0x1BDFC5D9,0x0BCFE7D5,0x00FFEBBB,0x1713EBAF,
  418.     0xD7002BF7,0xC5C9E507,0xFFC9D1DF,0xEFFFD9E5,0xF1BFB9F5,0x1F1BD7B5,
  419.     0x072D15C9,0xC1F51DFF,0x000FFDB7,0xBFF52BFF,0xB7D5073D,0xFFDDE1FD,
  420.     0xEFE72F2F,0xF9DFE70F,0x33EFD1CD,0x0F3335E1,0xE1BDFF1D,0x00000BDB,
  421.     0xE31F2327,0xCDA90B5D,0x3BF3C5E9,0x15FF001F,0x11FBEB07,0x3FF7BBBD,
  422.     0x002F2DCD,0xC9F1EF15,0x1DE1F1FF,0xF70F27F1,0xCFCFE537,0x3DF7A9C1,
  423.     0x1D25EFC1,0xDDFF19F7,0x070FD7AB,0x003745F7,0xBFE5450D,0xE5F100FF,
  424.     0x15032F11,0xB7D7F92F,0x25DFD1E1,0xFD35FBD1,0xF5FFFF47,0x00E9F7CF,
  425.     0xE12F45FF,0xDFC91B3B,0xE5B1D907,0x19F70713,0xFFC7CF13,0x37F7CD00,
  426.     0x331905D9,0xE51FFFFF,0x3F1FD7FB,0xEF0731FF,0xEB17172B,0x1DDBD9DF,
  427.     0x250DE900,0x1DEFE5E1,0x032DDFC7,0x273DF7D5,0xC1E521F7,0xDB1F1FDF,
  428.     0xEFEF000D,0xEFC9071F,0x09E7E1D1,0xFFF71BE5,0x0F0DEFE1,0x00EF0DDF,
  429.     0xCB1F3DF3,0xD1E5DF0D,0xEFD92731,0xCFED1F1F,0xEFBFD11F,0x2DFFD7E9,
  430.     0x07DBFF0F,0x00F7FFDF,0x1F23EBD7,0xF1D92731,0xD1C1E1F7,0x190DC9F9,
  431.     0xFFDFE327,0xF9DFCFE1,0x3733E1BD,0x1D0FE7FF,0x0DFFF1AF,0x27D9E3D1,
  432.     0xFFFFC3FF,0x17FFF7BF,0x0F1D3D03,0x05C1D7FF,0xDF00EFE3,0x1DFF23E1,
  433.     0xEFDDB7F1,0x2729B1EB,0xD9EB0DBB,0xC10925ED,0xD30FF1EF,0xC5002FD3,
  434.     0xDBAF070B,0xEFD1F11B,0x15FD2307,0x0DDDEB3F,0xF71DE7F3,0xE90D05FD,
  435.     0xF1F11D3D,0x0023FF1D,0xE1D70711,0xFFC11527,0x3BDBBF07,0x09FF1DE5,
  436.     0x00E5DFE5,0x00F1CD15,0xC10FF9F7,0xD1A1C11F,0x0DC9C109,0xEF25C1D1,
  437.     0x00DFDFC1,0x3507EFAF,0xE5230DD9,0xE9C10711,0xEFE9E9DB,0xEF03D11F,
  438.     0xBFCFE109,0x1F29BFC9,0xFB2DF3D5,0xC1151DE7,0x17F10FBF,0xD70027EF,
  439.     0xB1D70025,0xFFB9E100,0xBF1D050F,0xDDDFC113,0x0705DFD1,0xE923FF0F,
  440.     0xA1D51DFF,0x00E5FFC5,0xFFE51F27,0xCFB90F0D,0x2FCFA9D1,0x2DFF071F,
  441.     0xE115F71B,0x1F15D7F7,0xFF271DF9,0xB9C9E93F,0x15CF00FD,0x3D1DEBD1,
  442.     0x0FEFEF47,0x2F0701CD,0x0F45FFCF,0xDF170D2D,0xD3D1D1EB,0x25311F00,
  443.     0xFFEDF93B,0x29DFDB00,0x631537B9,0xCF192D05,0x2F1DDB0D,0x07133FD7,
  444.     0xC12B435B,0xF5E5C1FF,0xFFF500E1,0xDFF7071F,0xD7E5BFC7,0x4725FBB9,
  445.     0xD1C12B09,0xC100FFDF,0x23FF00D7,0xB7C52347,0xC1CBC50F,0x0DF7F1EF,
  446.     0xED05FF27,0x00BBBD0F,0x071725B5,0x00F9FF1B,0x01C10735,0x13F90FC3,
  447.     0x1BEFF54B,0x25F1BB11,0x0F1DC7E1,0x131F2F11,0xF10FBFF3,0x3B0B0FEF,
  448.     0xEF003FD1,0x1511D10D,0x3D0500BF,0xE1FF05E5,0x1739E109,0xD943E7B7,
  449.     0xE915292F,0xC70F17DD,0xB93D21F1,0xFFD14319,0xC3C11D17,0x00FF2DF9,
  450.     0x1795EFF5,0x0FFD2D17,0xD1E1270D,0xC1C1000D,0x3D33110F,0x9DDBDD4B,
  451.     0x0FC7F70B,0x63079DD1,0xC9012D0D,0xE1CDBF9F,0x23D9C1DF,0xEFDDE923,
  452.     0xCB8B9307,0x491DB191,0xBF11CBD5,0x00F7D7D7,0x4F2FCF89,0xBB53111D,
  453.     0xE9D1F1DF,0x0D000FBF,0xD72B1F31,0xBFB3E1FD,0x432DD9C9,0xB72D25F1,
  454.     0xA9DDDFF9,0x472F25A7,0x93193D1D,0xB1AF0F2D,0x1BCD00C1,0x9FFF3F4F,
  455.     0xF1B7C52B,0x37F7D7B5,0x012FFF57,0xC9C5EF1D,0x3F1FDFA1,0xBF002B3D,
  456.     0xB1A9D11D,0x43C9B1AB,0xF7FF2717,0x00EF971B,0x55FFBBBF,0xE95B15F1,
  457.     0xA1C1C12D,0x2D07E19F,0xFF05000F,0xBFBBF135,0x6D3BC19D,0x0D0D0DE9,
  458.     0xA1EBEFEB,0x0F2BBD8B,0xDB535915,0xA9E5BF25,0xE30007DB,0xE7533D00,
  459.     0xB39FCB5F,0x4BF71FC1,0x07352D00,0xEFDF0D3D,0x2FEDE7A7,0xC905573D,
  460.     0xC3F1F94D,0x11CFBB13,0x1DFF4F07,0xBDF1C717,0x3FFFCFEB,0x27DD31C7,
  461.     0xA9C9F955,0x4F0FE1FF,0x19DF2927,0xEFE7EF4F,0x0D279BBF,0x37452D03,
  462.     0x11D11D11,0xFF2FE9DF,0x472727FB,0xFFAB153D,0x152DC1C1,0xFF1DE9E1,
  463.     0x1709FF37,0x0723BFB5,0xD7553FC9,0xF1D9EF0B,0x0DE50BEF,0xD71547AD,
  464.     0xEBBFE917,0x5327F11F,0xCD3D39C1,0xC1FF0921,0x1100B7FF,0xAF1D5D31,
  465.     0xDBC73DFD,0x1DE1BD00,0x1FFF5B37,0xD19F15E3,0x3B1FBFEB,0xE9090027,
  466.     0xA1A31D49,0x3D0FB3E7,0xDFF1E137,0xE99FFF27,0x3BB5A9A3,0x0D4509FF,
  467.     0x079DD72D,0x2FE1E9D3,0x135FF1EF,0xCBCFD51D,0x512F2DC5,0xCB1BDFEB,
  468.     0x091F0BFF,0x4B1300E1,0xDF2B2F1D,0xFF13A9BF,0x15DF00E1,0xE7571D1F,
  469.     0xD1FFCDBF,0xFD2721AF,0xCDC9FF0F,0x87CF1329,0x0DE50FB9,0xFBCF0037,
  470.     0xCFBFC1FF,0x00FDCFC9,0x070B114F,0xC5F5F71D,0x3F1B0F11,0xEFC11B0D,
  471.     0xABC1C737,0x4BDFC1C5,0xFFD3FFC5,0xF1FFAD31,0x2FE9DFBF,0xE1333D1D,
  472.     0xE7C5A90D,0xEBE1E9AB,0x2515F5E9,0xEF8993FF,0x3F2FCDB9,0x13E72DCF,
  473.     0xCD0FFFFF,0x1F2DD1A7,0xB7034FFF,0xC927AB1F,0xDFE500CF,0xC72D3F17,
  474.     0xFFB7BF37,0x15350DB3,0xF5E70DE1,0xD1C11F3D,0x0033FFCF,0xDBEF172F,
  475.     0xC7A5F14B,0x07098DD1,0xFBEB3927,0xC9D1D7E9,0x1721BBDF,0xE9073DE7,
  476.     0xC182B72D,0x1DF1E1EF,0xB5EF1307,0x07BFE171,0x2D2FA5AD,0xE93D0327,
  477.     0x3DDBEFFF,0x0027BFAB,0xE1295315,0xEBC1DFEF,0x4D17C9F5,0xDF092FC9,
  478.     0xF1DFBF23,0x6939A5C7,0x9D251DD5,0xE113FF1F,0xFF1FCFBF,0xAF39651F,
  479.     0xDBC50FF1,0x1D1FE1CB,0x1D4D4113,0xC1AB25FF,0x1F57D7C1,0xC93D232D,
  480.     0xA1B73D3B,0x07F1B1D1,0xBF093F4B,0xF1A31D07,0x1FB7CDCD,0xE75537E7,
  481.     0xC193DF55,0x4FC3070D,0xCF33DF01,0xCDBFF57B,0x63C9CBC3,0xFF3BFF00,
  482.     0x2DD7F51D,0x4FD1BBBF,0x4B65472B,0xC7E900FF,0x5F0FBD0F,0x55570F07,
  483.     0x9D15DFEF,0x6D35B1A5,0xFF1729C5,0xD1454BF9,0x1DCDE187,0xDF4F4500,
  484.     0xB9DF001B,0xABEF0F9D,0x115703F1,0x89AF1347,0xD52335B5,0xFF0925E9,
  485.     0x9FB93D51,0x07C71FD1,0xCD0F174B,0xC1BFCF0D,0x0525E9E5,0xD91937E1,
  486.     0x0F00CF39,0x671707BF,0xED076900,0xF7F10F65,0x29D500F9,0x0F0DF907,
  487.     0x2BCFB1FF
  488. };
  489.  
  490.     /* Clock image run-dump. */
  491.  
  492. USHORT ClockMap[456] =
  493. {
  494.     0xFFFF,0xFFFF,0x8000,0x0FFF,0xFFFF,0xFF80,0xFFFF,0xFFC0,
  495.     0x1FFF,0x801F,0xFFFF,0xFF80,0xFFFF,0xF80F,0x8000,0x0F80,
  496.     0xFFFF,0xFF80,0xFFFF,0xC1C0,0x3FFF,0xE01E,0x1FFF,0xFF80,
  497.     0xFFFE,0x081F,0xF9F0,0xFFC0,0x43FF,0xFF80,0xFFF0,0x81FF,
  498.     0xF1E6,0x7FFC,0x087F,0xFF80,0xFFC0,0x0FE7,0xF9FE,0x7F3F,
  499.     0x800F,0xFF80,0xFF00,0x7FF3,0xF9F8,0xFE7F,0xF005,0xFF80,
  500.     0xFE01,0xFFF9,0xF9F3,0xFCFC,0xFC02,0xFF80,0xF803,0xFFFF,
  501.     0xF9E6,0x7FF3,0xFE00,0x7F80,0xF00C,0x7FFF,0xE060,0x7FCF,
  502.     0xF180,0x2F80,0xE01F,0x8FFF,0xFFFF,0xFF3F,0x8FC0,0x1780,
  503.     0xC03F,0xFFFF,0xFFFF,0xFCFF,0xFFE0,0x0B80,0xC07F,0xFFFF,
  504.     0xFFFF,0xF3FF,0xFFF0,0x1580,0x80FF,0xFFFF,0xFFFF,0xCFFF,
  505.     0xFFF8,0x0B80,0x80C3,0xFFFF,0xFFFF,0x3FFF,0xFE18,0x0580,
  506.     0x0199,0xFFFF,0xFFFC,0xFFFF,0xFCCC,0x0280,0x0199,0xFFFF,
  507.     0xFFF3,0xFFFF,0xFFCC,0x0500,0x01C1,0xFFFF,0xFF8F,0xFFFF,
  508.     0xFF1C,0x0280,0x01F9,0xFFFF,0xF021,0xFFFF,0xFFCC,0x0500,
  509.     0x01F3,0xFFFE,0x01F8,0x7FFF,0xFCCC,0x0280,0x80C7,0xFFC0,
  510.     0x3FFE,0x1FFF,0xFE18,0x0500,0x80FF,0xFC01,0xFFFF,0x87FF,
  511.     0xFFF8,0x0A80,0x807F,0xF81F,0xFFFF,0xE0FF,0xFFF0,0x1580,
  512.     0xC03F,0xFFFF,0xFFFF,0xF83F,0xFFE0,0x0B80,0xE01F,0x8FFF,
  513.     0xFFFF,0xFE0F,0x8FC0,0x1580,0xF00C,0x7FFF,0xFFC7,0xFF03,
  514.     0xF180,0x2B80,0xF803,0xFFFF,0xFF9F,0xFFC1,0xFE00,0x5780,
  515.     0xFC01,0xFFF9,0xFF3F,0xFCFF,0xFC00,0xAF80,0xFE00,0x7FF3,
  516.     0xFF07,0xFE7F,0xF001,0x5F80,0xFFC0,0x0FE7,0xFF33,0xFF3F,
  517.     0x800A,0xBF80,0xFFF0,0x81FF,0xFF33,0xFFFC,0x0855,0xFF80,
  518.     0xFFFE,0x081F,0xFF87,0xFFC0,0x02AF,0xFF80,0xFFFF,0xC1C0,
  519.     0x3FFF,0xE012,0x157F,0xFF80,0xFFFF,0xF80F,0x8000,0x0F80,
  520.     0xABFF,0xFF80,0xFFFF,0xFFC0,0x18FF,0x8015,0x5FFF,0xFF80,
  521.     0xFFFF,0xFFFE,0x8000,0x0AAB,0xFFFF,0xFF80,0xFFFF,0xFFFF,
  522.     0xFD55,0x55FF,0xFFFF,0xFF80,
  523.  
  524.     0x0000,0x0000,0x7FFF,0xF000,0x0000,0x0000,0x0000,0x003F,
  525.     0xE000,0x7FE0,0x0000,0x0000,0x0000,0x07F0,0x7FFF,0xF07F,
  526.     0x0000,0x0000,0x0000,0x3E3F,0xC000,0x1FE1,0xE000,0x0000,
  527.     0x0001,0xF7E0,0x060F,0x003F,0xBC00,0x0000,0x000F,0x7E00,
  528.     0x0E19,0x8003,0xF780,0x0000,0x003F,0xF018,0x0601,0x80C0,
  529.     0x7FF0,0x0000,0x00FF,0x800C,0x0607,0x0180,0x0FFA,0x0000,
  530.     0x01FE,0x0006,0x060C,0x0303,0x03FD,0x0000,0x07FC,0x0000,
  531.     0x0619,0x800C,0x01FF,0x8000,0x0FF3,0x8000,0x1F9F,0x8030,
  532.     0x0E7F,0xD000,0x1FE0,0x7000,0x0000,0x00C0,0x703F,0xE800,
  533.     0x3FC0,0x0000,0x0000,0x0300,0x001F,0xF400,0x3F80,0x0000,
  534.     0x0000,0x0C00,0x000F,0xEA00,0x7F00,0x0000,0x0000,0x3000,
  535.     0x0007,0xF400,0x7F3C,0x0000,0x0000,0xC000,0x01E7,0xFA00,
  536.     0xFE66,0x0000,0x0003,0x0000,0x0333,0xFD00,0xFE66,0x0000,
  537.     0x000C,0x0000,0x0033,0xFA80,0xFE3E,0x0000,0x0070,0x0000,
  538.     0x00E3,0xFD00,0xFE06,0x0000,0x0FDE,0x0000,0x0033,0xFA80,
  539.     0xFE0C,0x0001,0xFE07,0x8000,0x0333,0xFD00,0x7F38,0x003F,
  540.     0xC001,0xE000,0x01E7,0xFA80,0x7F00,0x03FE,0x0000,0x7800,
  541.     0x0007,0xF500,0x7F80,0x07E0,0x0000,0x1F00,0x000F,0xEA00,
  542.     0x3FC0,0x0000,0x0000,0x07C0,0x001F,0xF400,0x1FE0,0x7000,
  543.     0x0000,0x01F0,0x703F,0xEA00,0x0FF3,0x8000,0x0038,0x00FC,
  544.     0x0E7F,0xD400,0x07FC,0x0000,0x0060,0x003E,0x01FF,0xA800,
  545.     0x03FE,0x0006,0x00C0,0x0300,0x03FF,0x5000,0x01FF,0x800C,
  546.     0x00F8,0x0180,0x0FFE,0xA000,0x003F,0xF018,0x00CC,0x00C0,
  547.     0x7FF5,0x4000,0x000F,0x7E00,0x00CC,0x0003,0xF7AA,0x0000,
  548.     0x0001,0xF7E0,0x0078,0x003F,0xFD50,0x0000,0x0000,0x3E3F,
  549.     0xC000,0x1FED,0xEA80,0x0000,0x0000,0x07F0,0x7FFF,0xF07F,
  550.     0x5400,0x0000,0x0000,0x003F,0xE700,0x7FEA,0xA000,0x0000,
  551.     0x0000,0x0001,0x7FFF,0xF554,0x0000,0x0000,0x0000,0x0000,
  552.     0x02AA,0xAA00,0x0000,0x0000
  553. };
  554.  
  555.     /* This one binds the clock image data. */
  556.  
  557. struct Image ClockImage =
  558. {
  559.     0,0,
  560.     89,38,2,
  561.     (USHORT *)ClockMap,
  562.     0x03,0x00,
  563.     (struct Image *)NULL
  564. };
  565.  
  566.     /* The gadgets for the clock window. */
  567.  
  568. struct Gadget ClockGadget[2] =
  569. {
  570.     &ClockGadget[1],4,2, 88,38,GADGIMAGE | GADGHBOX,GADGIMMEDIATE | RELVERIFY,BOOLGADGET,(APTR)&ClockImage,NULL,NULL,0,NULL,0,NULL,
  571.     NULL,           0,0,294,42,GADGHNONE,           GADGIMMEDIATE,            WDRAGGING, NULL,             NULL,NULL,0,NULL,1,NULL
  572. };
  573.  
  574.     /* The clock window definitions. */
  575.  
  576. struct NewWindow NewClockWindow =
  577. {
  578.     0,0,
  579.     294,42,
  580.     1,3,
  581.     GADGETUP,
  582.     ACTIVATE | RMBTRAP,
  583.     (struct Gadget *)&ClockGadget[0],
  584.     (struct Image *)NULL,
  585.     (STRPTR)NULL,
  586.     (struct Screen *)NULL,
  587.     (struct BitMap *)NULL,
  588.     0,0,
  589.     0,0,
  590.     WBENCHSCREEN
  591. };
  592.  
  593.     /* Some more information text. */
  594.  
  595. struct IntuiText ClockTxt[4] =
  596. {
  597.     {1,0,2,98, 2,&DefaultFont,(UBYTE *)"This is DClock trying to",&ClockTxt[1]},
  598.     {1,0,2,98,10,&DefaultFont,(UBYTE *)"wake you up.  Click  the",&ClockTxt[2]},
  599.     {1,0,2,98,18,&DefaultFont,(UBYTE *)"clock to proceed.",       &ClockTxt[3]},
  600.     {3,0,0,98,31,&DefaultFont,(UBYTE *)"Alarm time » 12:12:12 « ", NULL}
  601. };
  602.  
  603.     /* Define the handler code as a function. */
  604.  
  605. extern void Handler();
  606.  
  607.     /* Some inline assembly code to deal with the
  608.      * input.device handler interrupt.
  609.      */
  610.  
  611. #asm
  612. _Handler:    MOVEM.L    A4,-(A7)    ; Save base register
  613.         MOVEM.L    A0/A1,-(A7)    ; Push both arguments onto stack
  614.  
  615.         JSR    _geta4#        ; Adjust the base register
  616.         JSR    _MyHandler    ; Call the handler routine
  617.  
  618.         ADDQ.L    #8,A7        ; Clear the contents of the stack
  619.  
  620.         MOVEM.L    (A7)+,A4    ; Restore the original base register
  621.  
  622.         RTS            ; Pass it to the next handler...
  623. #endasm
  624.  
  625.     /* MyHandler(Event,MyData) :
  626.      *
  627.      *    This is the main interface to the handler
  628.      *    routine.
  629.      */
  630.  
  631. struct InputEvent *
  632. MyHandler(Event)
  633. struct InputEvent *Event;
  634. {
  635.         /* User wants to toggle text and memory mode. */
  636.  
  637.     if(Event -> ie_Class == IECLASS_RAWKEY && Event -> ie_Code == 0x5F && Event -> ie_Qualifier == 0x8080)
  638.     {
  639.         Event -> ie_Class = IECLASS_NULL;
  640.  
  641.         if(DSeg -> Child)
  642.             Signal(DSeg -> Child,SIG_TOGGL);
  643.     }
  644.  
  645.         /* If we can use it, initialize the copyevent and signal
  646.          * the main process to produce a click.
  647.          */
  648.  
  649.     if(Event -> ie_Class == IECLASS_RAWKEY && !(Event -> ie_Code & IECODE_UP_PREFIX) && DSeg -> Click)
  650.     {
  651.         CopyEvent . ie_Class    = Event -> ie_Class;
  652.         CopyEvent . ie_Code    = Event -> ie_Code;
  653.         CopyEvent . ie_Qualifier= Event -> ie_Qualifier;
  654.  
  655.             /* This is safe from interrupt code, or
  656.              * at least should be.
  657.              */
  658.  
  659.         if(DSeg -> Child)
  660.             Signal(DSeg -> Child,SIG_CLICK);
  661.     }
  662.  
  663.         /* I had a lot of trouble getting DClock-Handler to
  664.          * work with timer.device. Well, the only thing
  665.          * happening in time were system crashes, so I
  666.          * decided to use the timer entries of the
  667.          * InputEvent structures.
  668.          */
  669.  
  670.     if(Event -> ie_TimeStamp . tv_secs != DSeg -> LastSecs)
  671.     {
  672.         DSeg -> LastSecs = Event -> ie_TimeStamp . tv_secs;
  673.  
  674.         if(DSeg -> Child)
  675.             Signal(DSeg -> Child,SIG_TIMER);
  676.     }
  677.  
  678.     return(Event);
  679. }
  680.  
  681.     /* Click() :
  682.      *
  683.      *    Produces the click (or what did you expect?).
  684.      */
  685.  
  686. void
  687. Click()
  688. {
  689.     struct Message *AudioMsg;
  690.     char PrimaryBuffer[11];    /* Rawkey conversion buffer. */
  691.     register short i;
  692.  
  693.         /* Erase the buffer. */
  694.  
  695.     for(i = 0 ; i < 11 ; i++)
  696.         PrimaryBuffer[i] = 0;
  697.  
  698.         /* Convert the input event according to the
  699.          * current keymap settings.
  700.          */
  701.  
  702.     RawKeyConvert(&CopyEvent,PrimaryBuffer,10,NULL);
  703.  
  704.         /* If it didn't produce a sensible result,
  705.          * don't click.
  706.          */
  707.  
  708.     if(!PrimaryBuffer[0])
  709.         return;
  710.  
  711.     Audio -> ioa_Volume = DSeg -> ClickVolume;
  712.  
  713.         /* If it's still resounding, abort it. */
  714.  
  715. Tick:    if(!CheckIO(Audio))
  716.         AbortIO(Audio);
  717.  
  718.         /* Let it click. */
  719.  
  720.     BeginIO(Audio);
  721. }
  722.  
  723.     /* FlushSound() :
  724.      *
  725.      *    Send the sound control data to NIL:
  726.      */
  727.  
  728. void
  729. FlushSound()
  730. {
  731.         /* Audio device still open? */
  732.  
  733.     if(Audio -> ioa_Request . io_Device)
  734.     {
  735.         if(!CheckIO(Audio))
  736.             WaitIO(Audio);
  737.  
  738.             /* Free the channel(s). */
  739.  
  740.         Audio -> ioa_Request . io_Command = ADCMD_FREE;
  741.         DoIO(Audio);
  742.  
  743.         CloseDevice(Audio);
  744.     }
  745.  
  746.         /* Free the audio control block. */
  747.  
  748.     if(Audio)
  749.         FreeMem(Audio,sizeof(struct IOAudio));
  750.  
  751.         /* Delete the replyport. */
  752.  
  753.     if(AudioPort)
  754.         DeletePort(AudioPort);
  755. }
  756.  
  757.     /* InitSound() :
  758.      *
  759.      *    Sets up the audio control structures.
  760.      */
  761.  
  762. BOOL
  763. InitSound()
  764. {
  765.     if(!(Audio = (struct IOAudio *)AllocMem(sizeof(struct IOAudio),MEMF_PUBLIC | MEMF_CLEAR)))
  766.         return(FALSE);
  767.  
  768.     if(!(AudioPort = (struct MsgPort *)CreatePort(NULL,0)))
  769.         return(FALSE);
  770.  
  771.         /* Try to allocate a vacant channel. Sam Dicker suggests
  772.          * channel allocation precedence 90 for annunciators.
  773.          */
  774.  
  775.     Audio -> ioa_Request . io_Command            = ADCMD_ALLOCATE;
  776.     Audio -> ioa_Request . io_Message . mn_Node . ln_Pri    = 90;
  777.     Audio -> ioa_Request . io_Message . mn_ReplyPort    = AudioPort;
  778.     Audio -> ioa_Data                    = AnyChannel;
  779.     Audio -> ioa_Length                    = 4;
  780.  
  781.         /* Open the channel. */
  782.  
  783.     if(OpenDevice(AUDIONAME,0,Audio,0))
  784.         return(FALSE);
  785.  
  786.         /* Prepare it for the click. */
  787.  
  788.     Audio -> ioa_Request . io_Flags        = ADIOF_PERVOL | ADIOF_NOWAIT;
  789.     Audio -> ioa_Request . io_Command    = CMD_WRITE;
  790.     Audio -> ioa_Period            = 180;
  791.     Audio -> ioa_Volume            = 0;
  792.     Audio -> ioa_Length            = 270;
  793.     Audio -> ioa_Data            = (UBYTE *)SoundData;
  794.     Audio -> ioa_Cycles            = 1;
  795.  
  796.         /* This first sound will not be heard since
  797.          * the audio.device needs a sound to be played
  798.          * at least once to work properly. Since there
  799.          * was no keypress yet, don't confuse the user.
  800.          */
  801.  
  802.     BeginIO(Audio);
  803.     WaitIO(Audio);
  804.  
  805.         /* Adjust the volume now. */
  806.  
  807.     Audio -> ioa_Volume = 64;
  808.  
  809.     return(TRUE);
  810. }
  811.  
  812.     /* InitHandler() :
  813.      *
  814.      *    Open the console.device for keymap translation
  815.      *    and add the input.device handler.
  816.      */
  817.  
  818. BOOL
  819. InitHandler()
  820. {
  821.     if(OpenDevice("console.device",-1,&ConStdReq,0))
  822.         return(FALSE);
  823.  
  824.     ConsoleDevice = (long)ConStdReq . io_Device;
  825.  
  826.     if(!(InputDevPort = (struct MsgPort *)CreatePort(NULL,0)))
  827.         return(FALSE);
  828.  
  829.     if(!(InputRequestBlock = (struct IOStdReq *)CreateStdIO(InputDevPort)))
  830.         return(FALSE);
  831.  
  832.     if(OpenDevice("input.device",0,InputRequestBlock,0))
  833.         return(FALSE);
  834.  
  835.     HandlerStuff . is_Code        = Handler;
  836.     HandlerStuff . is_Node . ln_Pri    = 60;
  837.     HandlerStuff . is_Node . ln_Name= "DClock-Handler";
  838.  
  839.     InputRequestBlock -> io_Command    = IND_ADDHANDLER;
  840.     InputRequestBlock -> io_Data    = (APTR)&HandlerStuff;
  841.  
  842.     DoIO(InputRequestBlock);
  843.  
  844.     return(TRUE);
  845. }
  846.  
  847.     /* FlushHandler() :
  848.      *
  849.      *    Closes the console.device and removes the
  850.      *    input.device handler from the chain.
  851.      */     
  852.  
  853. void
  854. FlushHandler()
  855. {
  856.     if(ConsoleDevice)
  857.         CloseDevice(&ConStdReq);
  858.  
  859.     if(InputRequestBlock -> io_Device)
  860.     {
  861.         InputRequestBlock -> io_Command    = IND_REMHANDLER;
  862.         InputRequestBlock -> io_Data    = (APTR)&HandlerStuff;
  863.  
  864.         DoIO(InputRequestBlock);
  865.  
  866.         CloseDevice(InputRequestBlock);
  867.     }
  868.  
  869.     if(InputRequestBlock)
  870.         DeleteStdIO(InputRequestBlock);
  871.  
  872.     if(InputDevPort)
  873.         DeletePort(InputDevPort);
  874. }
  875.  
  876.     /* ModifiedCloseWBench():
  877.      *
  878.      *    Tells DClock to close its window before the
  879.      *    Workbench screen gets closed.
  880.      */
  881.  
  882. void
  883. ModifiedCloseWBench()
  884. {
  885.     if(Window)
  886.     {
  887.         register struct Task *ThisTask = (struct Task *)FindTask(NULL);
  888.         register long CurrentPri;
  889.  
  890.             /* Shut down... */
  891.  
  892.         Signal(DSeg -> Child,SIG_BENCH);
  893.  
  894.             /* Careful - rather rude window close check,
  895.              * don't waste too much time in the loop.
  896.              */
  897.  
  898.         CurrentPri = SetTaskPri(ThisTask,-1);
  899.         while(Window);
  900.         SetTaskPri(ThisTask,CurrentPri);
  901.     }
  902. }
  903.  
  904.     /* Define these externally to make the SetFunction() calls
  905.      * possible.
  906.      */
  907.  
  908. extern void NewDisplayBeep();
  909. extern void NewCloseWBench();
  910.  
  911.     /* The library offset pointers (old ones). */
  912.  
  913. long OldDisplayBeep;
  914. long OldCloseWBench;
  915.  
  916.     /* Embedded assembly fragment, handles our replacement call
  917.      * for DisplayBeep().
  918.      */
  919.  
  920. #asm
  921. _NewDisplayBeep:MOVEM.L    D2/D3/A4/A6,-(SP)    ; Save some registers
  922.  
  923.         MOVE.L    A0,-(SP)        ; Push NewWindow onto stack
  924.  
  925.         JSR    _geta4#            ; Tickle the base register
  926.         JSR    _ModifiedDisplayBeep    ; Call our magic creation
  927.  
  928.         ADD.W    #4,SP            ; Clean the stack up
  929.  
  930.         CLR.L    D0            ; Just in case...
  931.  
  932.         MOVEM.L    (SP)+,D2/D3/A4/A6    ; Restore some registers
  933.  
  934.         RTS                ; Bye...
  935.  
  936. _NewCloseWBench:MOVEM.L    D2/D3/A4/A6,-(SP)    ; Rewritten CloseWBench()
  937.                         ; function.
  938.         JSR    _geta4#
  939.         JSR    _ModifiedCloseWBench
  940.  
  941.         MOVE.L  _OldCloseWBench,A1
  942.  
  943.         MOVEM.L    (SP)+,D2/D3/A4/A6
  944.  
  945.         JMP    (A1)
  946. #endasm
  947.  
  948.     /* AudioBeep():
  949.      *
  950.      *    Funny beep routine, originally developed by
  951.      *    John Hodgson as a NewZAP support routine.
  952.      *    Carefully rewritten to be reentrant beyond
  953.      *    any measure (Yechh!).
  954.      */
  955.  
  956. void
  957. AudioBeep()
  958. {
  959.     register struct IOAudio    *AudioBlock;
  960.     register struct MsgPort    *ReplyPort;
  961.     register UBYTE        *WaveMap;
  962.  
  963.         /* No beeping? */
  964.  
  965.     if(!DSeg -> Beep)
  966.         return;
  967.  
  968.         /* Eight bytes for channel allocation and
  969.          * square wave? Not bad, what do you think?
  970.          */
  971.  
  972.     if(WaveMap = (UBYTE *)AllocMem(8,MEMF_CHIP))
  973.     {
  974.             /* Cheapo square wave. */
  975.  
  976.         WaveMap[0] = ~127;
  977.         WaveMap[1] = ~127;
  978.         WaveMap[2] =  127;
  979.         WaveMap[3] =  127;
  980.  
  981.             /* This will give us any audio channel. */
  982.  
  983.         WaveMap[4] = 1;
  984.         WaveMap[5] = 2;
  985.         WaveMap[6] = 4;
  986.         WaveMap[7] = 8;
  987.  
  988.             /* Allocate some driver memory. */
  989.  
  990.         if(AudioBlock = (struct IOAudio *)AllocMem(sizeof(struct IOAudio),MEMF_PUBLIC | MEMF_CLEAR))
  991.         {
  992.                 /* Time for a replyport? */
  993.  
  994.             if(ReplyPort = (struct MsgPort *)CreatePort(NULL,0))
  995.             {
  996.                     /* Setup initial driver data. */
  997.  
  998.                 AudioBlock -> ioa_Data                    = &WaveMap[4];
  999.                 AudioBlock -> ioa_Length                = 4;
  1000.                 AudioBlock -> ioa_Request . io_Message . mn_ReplyPort    = ReplyPort;
  1001.                 AudioBlock -> ioa_Request . io_Message . mn_Node.ln_Pri    = 90;
  1002.  
  1003.                     /* Allocate the channels on the fly. */
  1004.  
  1005.                 if(!OpenDevice("audio.device",0,AudioBlock,0))
  1006.                 {
  1007.                     AudioBlock -> ioa_Request . io_Command    = CMD_WRITE;
  1008.                     AudioBlock -> ioa_Request . io_Flags    = ADIOF_PERVOL;
  1009.                     AudioBlock -> ioa_Period        = 447;
  1010.                     AudioBlock -> ioa_Volume        = 64 / 2;
  1011.                     AudioBlock -> ioa_Cycles        = 150;
  1012.                     AudioBlock -> ioa_Data            = &WaveMap[0];
  1013.                     AudioBlock -> ioa_Length        = 4;
  1014.  
  1015.                         /* Beeep! */
  1016.  
  1017.                     BeginIO(AudioBlock);
  1018.                     WaitIO(AudioBlock);
  1019.  
  1020.                         /* Tick! */
  1021.  
  1022.                     CloseDevice(AudioBlock);
  1023.                 }
  1024.  
  1025.                 DeletePort(ReplyPort);
  1026.             }
  1027.  
  1028.             FreeMem(AudioBlock,sizeof(struct IOAudio));
  1029.         }
  1030.  
  1031.         FreeMem(WaveMap,8);
  1032.     }
  1033. }
  1034.  
  1035.     /* VideoBeep(Screen,Perform):
  1036.      *
  1037.      *    Handles the visual part of the DisplayBeep,
  1038.      *    flashes a particular screen or restores its
  1039.      *    original colour (well, hope so).
  1040.      */
  1041.  
  1042. void
  1043. VideoBeep(Screen,Perform)
  1044. register struct Screen *Screen;
  1045. register BOOL Perform;
  1046. {
  1047.         /* Beep this screen? */
  1048.  
  1049.     if(Perform)
  1050.     {
  1051.             /* Is it already beeping? */
  1052.  
  1053.         if(!(Screen -> Flags & BEEPING))
  1054.         {
  1055.             register UBYTE R,G,B;
  1056.  
  1057.                 /* This one's beeping. */
  1058.  
  1059.             Screen -> Flags |= BEEPING;
  1060.  
  1061.                 /* Don't forget this one. */
  1062.  
  1063.             Screen -> SaveColor0 = GetRGB4(Screen -> ViewPort . ColorMap,0);
  1064.  
  1065.                 /* Reverse the colour. */
  1066.  
  1067.             R = ((Screen -> SaveColor0 >> 8) & 0xF) ^ 0xF;
  1068.             G = ((Screen -> SaveColor0 >> 4) & 0xF) ^ 0xF;
  1069.             B = ((Screen -> SaveColor0     ) & 0xF) ^ 0xF;
  1070.  
  1071.                 /* Set it. */
  1072.  
  1073.             SetRGB4(&Screen -> ViewPort,0,R,G,B);
  1074.         }
  1075.     }
  1076.     else
  1077.     {
  1078.             /* Is this one beeping? */
  1079.  
  1080.         if(Screen -> Flags & BEEPING)
  1081.         {
  1082.             register UBYTE R,G,B;
  1083.  
  1084.                 /* This one isn't beeping any longer. */
  1085.  
  1086.             Screen -> Flags &= ~BEEPING;
  1087.  
  1088.                 /* Restore the saved colour. */
  1089.  
  1090.             R = ((Screen -> SaveColor0 >> 8) & 0xF);
  1091.             G = ((Screen -> SaveColor0 >> 4) & 0xF);
  1092.             B = ((Screen -> SaveColor0     ) & 0xF);
  1093.  
  1094.             SetRGB4(&Screen -> ViewPort,0,R,G,B);
  1095.         }
  1096.     }
  1097. }
  1098.  
  1099.     /* ModifiedDisplayBeep(Screen):
  1100.      *
  1101.      *    Magic replacement for usual DisplayBeep()
  1102.      *    function.
  1103.      */
  1104.  
  1105. void
  1106. ModifiedDisplayBeep(Screen)
  1107. register struct Screen *Screen;
  1108. {
  1109.     static BOOL StillBeeping = FALSE;
  1110.  
  1111.     if(StillBeeping)
  1112.         return;
  1113.  
  1114.     StillBeeping = TRUE;
  1115.  
  1116.         /* Flash a particular screen. */
  1117.  
  1118.     if(Screen)
  1119.     {
  1120.         Forbid();
  1121.  
  1122.         VideoBeep(Screen,TRUE);
  1123.         AudioBeep();
  1124.         VideoBeep(Screen,FALSE);
  1125.  
  1126.         Permit();
  1127.     }
  1128.     else
  1129.     {
  1130.             /* Flash all screens. */
  1131.  
  1132.         register ULONG IntuiLock;
  1133.  
  1134.         Forbid();
  1135.  
  1136.             /* Where's the first one? Has anybody
  1137.              * used the LockIBase() function so
  1138.              * far (save me)?
  1139.              */
  1140.  
  1141.         IntuiLock = LockIBase(NULL);
  1142.         Screen = IntuitionBase -> FirstScreen;
  1143.         UnlockIBase(IntuiLock);
  1144.  
  1145.             /* Walk through the screens flashing them all. */
  1146.  
  1147.         do
  1148.             VideoBeep(Screen,TRUE);
  1149.         while(Screen = Screen -> NextScreen);
  1150.  
  1151.             /* Let it resound. */
  1152.  
  1153.         AudioBeep();
  1154.  
  1155.             /* Again: where's the first screen? */
  1156.  
  1157.         IntuiLock = LockIBase(NULL);
  1158.         Screen = IntuitionBase -> FirstScreen;
  1159.         UnlockIBase(IntuiLock);
  1160.  
  1161.         do
  1162.             VideoBeep(Screen,FALSE);
  1163.         while(Screen = Screen -> NextScreen);
  1164.  
  1165.         Permit();
  1166.     }
  1167.  
  1168.     StillBeeping = FALSE;
  1169. }
  1170.  
  1171.     /* PrintIt(TimeBuff):
  1172.      *
  1173.      *    Prints the formatted string into the Workbench title bar.
  1174.      */
  1175.  
  1176. void
  1177. PrintIt(TimeBuff)
  1178. UBYTE *TimeBuff;
  1179. {
  1180.     TimeString . IText = TimeBuff;
  1181.  
  1182.     TimeString . FrontPen    = DSeg -> TextColour;
  1183.     TimeString . BackPen    = DSeg -> BackColour;
  1184.  
  1185.     PrintIText(RPort,&TimeString,0,0);
  1186. }
  1187.  
  1188.     /* Some more embedded assembly language code, originally
  1189.      * written by Justin V. McCormick. Uses the ROM printf
  1190.      * routine to generate a formatted string, then calls
  1191.      * PrintIt to print it somewhere. This fragment once was
  1192.      * part of Justin's 'Emit' program.
  1193.      */
  1194.  
  1195. #asm
  1196. _LVORawDoFmt    EQU    $FFFFFDF6
  1197.  
  1198. stuffchar:    MOVE.B    D0,(A3)+    ; Puts a character into the
  1199.         RTS            ; char-buffer.
  1200.  
  1201.         XDEF    _Format        ; Make it known
  1202.  
  1203. _Format:    MOVE.L     4(SP),D1    ; Take over the args
  1204.         MOVE.L     8(SP),D0
  1205.         LEA    12(SP),A1
  1206.  
  1207.         MOVEM.L    A0-A3,-(SP)    ; Save these
  1208.  
  1209.         MOVE.L    D1,A3        ; Do the formatting
  1210.         MOVE.L    D0,A0
  1211.         LEA    stuffchar(PC),A2
  1212.         MOVE.L    4,A6
  1213.         JSR    _LVORawDoFmt(A6)
  1214.  
  1215.         MOVEM.L    (SP)+,A0-A3    ; Restore registers
  1216.         CLR.L    D0        ; and return safely.
  1217.  
  1218.         RTS
  1219. #endasm
  1220.  
  1221.     /* Ring():
  1222.      *
  1223.      *    This one rings the bell of the alarm clock.
  1224.      */
  1225.  
  1226. void
  1227. Ring()
  1228. {
  1229.     register struct IOAudio    *AudioBlock;
  1230.     register struct MsgPort    *ReplyPort;
  1231.  
  1232.     struct Screen        PublicScreen;
  1233.     struct Window        *ClockWindow;
  1234.     struct IntuiMessage    *Massage;
  1235.  
  1236.     ULONG        Class;
  1237.     USHORT        Code;
  1238.     struct Gadget    *ID;
  1239.  
  1240.     ULONG IntuiLock;
  1241.     struct View *ViewLord;
  1242.  
  1243.     short DyOffset,PlusY;
  1244.  
  1245.         /* No alarm? */
  1246.  
  1247.     if(!DSeg -> Alarm)
  1248.         return;
  1249.  
  1250.         /* Knockin' on heaven's door... */
  1251.  
  1252.     OpenWorkBench();
  1253.  
  1254.         /* Center the clock window. */
  1255.  
  1256.     GetScreenData(&PublicScreen,sizeof(struct Screen),WBENCHSCREEN,NULL);
  1257.  
  1258.     NewClockWindow . LeftEdge = (PublicScreen . Width - NewClockWindow . Width) / 2;
  1259.     NewClockWindow . TopEdge = (PublicScreen . Height - NewClockWindow . Height) / 2;
  1260.  
  1261.         /* Open it and paint the background. */
  1262.  
  1263.     if(!(ClockWindow = (struct Window *)OpenWindow(&NewClockWindow)))
  1264.         return;
  1265.  
  1266.     SetAPen(ClockWindow -> RPort,1);
  1267.  
  1268.     RectFill(ClockWindow -> RPort,2,1,ClockWindow -> Width - 3,ClockWindow -> Height - 2);
  1269.  
  1270.     RefreshGadgets(&ClockGadget[0],ClockWindow,NULL);
  1271.  
  1272.         /* Adjust the contents of the alarm time string. */
  1273.  
  1274.     Format(ClockTxt[3] . IText,"Alarm time » %2ld:%02ld:%02ld «",DSeg -> AlarmHour,DSeg -> AlarmMinute,DSeg -> AlarmSecond);
  1275.  
  1276.     PrintIText(ClockWindow -> RPort,&ClockTxt[0],0,0);
  1277.  
  1278.         /* Allocate some driver memory. */
  1279.  
  1280.     if(AudioBlock = (struct IOAudio *)AllocMem(sizeof(struct IOAudio),MEMF_PUBLIC | MEMF_CLEAR))
  1281.     {
  1282.             /* Time for a replyport? */
  1283.  
  1284.         if(ReplyPort = (struct MsgPort *)CreatePort(NULL,0))
  1285.         {
  1286.                 /* Setup initial driver data. */
  1287.  
  1288.             AudioBlock -> ioa_Data                    = &AnyChannel[0];
  1289.             AudioBlock -> ioa_Length                = 4;
  1290.             AudioBlock -> ioa_Request . io_Message . mn_ReplyPort    = ReplyPort;
  1291.             AudioBlock -> ioa_Request . io_Message . mn_Node.ln_Pri    = 90;
  1292.  
  1293.                 /* Allocate the channels on the fly. */
  1294.  
  1295.             if(!OpenDevice("audio.device",0,AudioBlock,0))
  1296.             {
  1297.                 AudioBlock -> ioa_Request . io_Command    = CMD_WRITE;
  1298.                 AudioBlock -> ioa_Request . io_Flags    = ADIOF_PERVOL;
  1299.                 AudioBlock -> ioa_Period        = 308;
  1300.                 AudioBlock -> ioa_Volume        = 64;
  1301.                 AudioBlock -> ioa_Cycles        = 8;
  1302.                 AudioBlock -> ioa_Data            = (UBYTE *)&RingData[0];
  1303.                 AudioBlock -> ioa_Length        = 7326;
  1304.  
  1305.                 IntuiLock = LockIBase(NULL);
  1306.                 ViewLord = &IntuitionBase -> ViewLord;
  1307.                 UnlockIBase(IntuiLock);
  1308.  
  1309.                 DyOffset = ViewLord -> DyOffset;
  1310.  
  1311.                     /* Ring! */
  1312.  
  1313.                 BeginIO(AudioBlock);
  1314.  
  1315.                 WBenchToFront();
  1316.  
  1317.                     /* Ring until somebody clicked our window. */
  1318.  
  1319.                 FOREVER
  1320.                 {
  1321.                         /* Cycles already finished. */
  1322.  
  1323.                     if(CheckIO(AudioBlock))
  1324.                         BeginIO(AudioBlock);
  1325.  
  1326.                     Class = Code = NULL;
  1327.  
  1328.                     if(Massage = (struct IntuiMessage *)GetMsg(ClockWindow -> UserPort))
  1329.                     {
  1330.                         Class = Massage -> Class;
  1331.                         Code  = Massage -> Code;
  1332.                         ID    = (struct Gadget *)Massage -> IAddress;
  1333.  
  1334.                         ReplyMsg(Massage);
  1335.  
  1336.                         if(Class == GADGETUP && !ID -> GadgetID)
  1337.                             break;
  1338.                     }
  1339.  
  1340.                     PlusY = 1 - RangeRand(3);
  1341.  
  1342.                         /* Make the view vibrate. */
  1343.  
  1344.                     if(DyOffset + PlusY >= 0)
  1345.                         ViewLord -> DyOffset = DyOffset + PlusY;
  1346.  
  1347.                     RethinkDisplay();
  1348.  
  1349.                         /* Wait a tick. */
  1350.  
  1351.                     Delay(1);
  1352.                 }
  1353.  
  1354.                 ViewLord -> DyOffset = DyOffset;
  1355.                 RethinkDisplay();
  1356.  
  1357.                     /* Still ringing? */
  1358.  
  1359.                 if(!CheckIO(AudioBlock))
  1360.                     AbortIO(AudioBlock);
  1361.  
  1362.                     /* Tick! */
  1363.  
  1364.                 CloseDevice(AudioBlock);
  1365.             }
  1366.  
  1367.             DeletePort(ReplyPort);
  1368.         }
  1369.  
  1370.         FreeMem(AudioBlock,sizeof(struct IOAudio));
  1371.     }
  1372.  
  1373.     CloseWindow(ClockWindow);
  1374. }
  1375.  
  1376.     /* ShowTime(ReallyDoIt):
  1377.      *
  1378.      *    Yes, it's Showtime! This one compiles the date/timestring
  1379.      *    and prints it.
  1380.      */
  1381.  
  1382. void
  1383. ShowTime(ReallyDoIt)
  1384. BOOL ReallyDoIt;
  1385. {
  1386.     UBYTE TempBuff[30];
  1387.  
  1388.     static char *Months[12] =
  1389.     {
  1390.         "Jan","Feb","Mar",
  1391.         "Apr","May","Jun",
  1392.         "Jul","Aug","Sep",
  1393.         "Oct","Nov","Dec"
  1394.     };
  1395.  
  1396.     static char *Days[7] =
  1397.     {
  1398.         "Sun",    /* Note: these have to appear right in this order. */
  1399.         "Mon",
  1400.         "Tue",
  1401.         "Wed",
  1402.         "Thu",
  1403.         "Fri",
  1404.         "Sat"
  1405.     };
  1406.  
  1407.     static char *LongDays[7] =
  1408.     {
  1409.         "Sunday",
  1410.         "Monday",
  1411.         "Tuesday",
  1412.         "Wednesday",
  1413.         "Thursday",
  1414.         "Friday",
  1415.         "Saturday"
  1416.     };
  1417.  
  1418.     static char DateBuff[15],TimeBuff[10],Printed = FALSE;
  1419.  
  1420.     struct DateStamp Date;
  1421.  
  1422.     long n,Month,Day,Year;
  1423.  
  1424.     DateStamp(&Date);
  1425.  
  1426.         /* Credits go to Tom Rokicki for his DateStamp
  1427.          * conversion routine.
  1428.          */
  1429.  
  1430.     n = Date . ds_Days - 2251;
  1431.     Year = (4 * n + 3) / 1461;
  1432.     n -= 1461 * Year / 4;
  1433.     Year += 1984;
  1434.     Month = (5 * n + 2) / 153;
  1435.     Day = n - (153 * Month + 2) / 5 + 1;
  1436.     Month += 3;
  1437.  
  1438.     if(Month > 12)
  1439.     {
  1440.         Year++;
  1441.         Month -= 12;
  1442.     }
  1443.  
  1444.         /* Took some time to develop the weekday conversion.
  1445.          * Please don't ask me how it works, I really don't know.
  1446.          * The formula was translated from BASIC, which was
  1447.          * quite a tricky thing to do: I haven't done anything
  1448.          * in BASIC for at least 2 years.
  1449.          */
  1450.  
  1451.     if(ReallyDoIt)
  1452.     {
  1453.         Format(TempBuff,"%s %02ld-%s-%02ld %02ld:%02ld:%02ld",
  1454.             Days[(Day + Year + (Year - (Month < 3)) / 4 + 3 * Month - 2 * (Month > 2) - (Month - 1 - (Month > 8)) / 2 + 2) % 7],
  1455.             Day,
  1456.             Months[Month - 1],
  1457.             Year - 1900,
  1458.             Date . ds_Minute / 60,
  1459.             Date . ds_Minute % 60,
  1460.             Date . ds_Tick / TICKS_PER_SECOND);
  1461.  
  1462.         PrintIt(TempBuff);
  1463.     }
  1464.  
  1465.     if((!(Date . ds_Tick / TICKS_PER_SECOND) || !Printed) && DSeg -> SetEnv)
  1466.     {
  1467.         Printed = TRUE;
  1468.  
  1469.         Format(DateBuff,"%02ld-%s-%02ld",Day,Months[Month - 1],Year - 1900);
  1470.         Format(TimeBuff,"%02ld:%02ld",Date . ds_Minute / 60,Date . ds_Minute % 60);
  1471.  
  1472.         setenv("DAY",LongDays[(Day + Year + (Year - (Month < 3)) / 4 + 3 * Month - 2 * (Month > 2) - (Month - 1 - (Month > 8)) / 2 + 2) % 7]);
  1473.         setenv("DATE",DateBuff);
  1474.         setenv("TIME",TimeBuff);
  1475.     }
  1476. }
  1477.  
  1478.     /* MaxMemSize(MemType):
  1479.      *
  1480.      *    Returns the length of memory block of a special
  1481.      *    kind. Borrowed from Louis A. Mamakos' GfxMem 0.4.
  1482.      */
  1483.  
  1484. ULONG
  1485. MaxMemSize(MemType)
  1486. ULONG MemType;
  1487. {
  1488.     ULONG BlockSize = 0;
  1489.     struct MemHeader *MemHeader;
  1490.     extern struct ExecBase *SysBase;
  1491.  
  1492.     Forbid();
  1493.  
  1494.         /* Walk through the memory lists adding the
  1495.          * amount of memory bound to them.
  1496.          */
  1497.  
  1498.     for(MemHeader = (struct MemHeader *)SysBase -> MemList . lh_Head ; MemHeader -> mh_Node . ln_Succ ; MemHeader = (struct MemHeader *)MemHeader -> mh_Node . ln_Succ)
  1499.         if(MemHeader -> mh_Attributes & MemType)
  1500.             BlockSize += ((ULONG)MemHeader -> mh_Upper - (ULONG)MemHeader -> mh_Lower);
  1501.  
  1502.     Permit();
  1503.  
  1504.     return(BlockSize);
  1505. }
  1506.  
  1507.     /* FindTheBench():
  1508.      *
  1509.      *    Tries to locate the Workbench screen in the linked list
  1510.      *    of system screens. This is rather a rude method and should
  1511.      *    be exercised only while task-switching is forbidden.
  1512.      */
  1513.  
  1514. struct Screen *
  1515. FindTheBench()
  1516. {
  1517.     register struct Screen *WBench;
  1518.     register ULONG IntuiLock;
  1519.  
  1520.         /* Start with the first one. */
  1521.  
  1522.     IntuiLock = LockIBase(NULL);
  1523.     WBench = IntuitionBase -> FirstScreen;
  1524.     UnlockIBase(IntuiLock);
  1525.  
  1526.         /* Scan the list... */
  1527.  
  1528.     do
  1529.     {
  1530.             /* The type we want? */
  1531.  
  1532.         if((WBench -> Flags & SCREENTYPE) == WBENCHSCREEN)
  1533.             return(WBench);
  1534.     }
  1535.     while(WBench = WBench -> NextScreen);
  1536.  
  1537.         /* Failed! */
  1538.  
  1539.     return(NULL);
  1540. }
  1541.  
  1542.     /* PickClip():
  1543.      *
  1544.      *    Transfers the contents of the DClock window to
  1545.      *    the Workbench screen bar layer.
  1546.      */
  1547.  
  1548. void
  1549. PickClip()
  1550. {
  1551.         /* This is going to be a very long line. */
  1552.  
  1553.     ClipBlit(RPort,0,0,
  1554.         Window -> WScreen -> BarLayer -> rp,LeftEdge,1,
  1555.         Width,Height,0xC0);
  1556. }
  1557.  
  1558.     /* ShutDown():
  1559.      *
  1560.      *    Closes DClock and waits for removal.
  1561.      */
  1562.  
  1563. void
  1564. ShutDown()
  1565. {
  1566.     register long j;
  1567.  
  1568.         /* Restore system functions. */
  1569.  
  1570.     Forbid();
  1571.     SetFunction(IntuitionBase,-0x60,OldDisplayBeep);
  1572.     SetFunction(IntuitionBase,-0x4E,OldCloseWBench);
  1573.     Permit();
  1574.  
  1575.     FlushHandler();
  1576.     FlushSound();
  1577.  
  1578.     if(Window)
  1579.     {
  1580.         SetRast(RPort,1);
  1581.  
  1582.         PickClip();
  1583.  
  1584.         CloseWindow(Window);
  1585.     }
  1586.  
  1587.     for(j = 0 ; j < 2 ; j++)
  1588.         if(DummyMap . Planes[j])
  1589.             FreeMem(DummyMap . Planes[j],Byte(Width) * 8);
  1590.  
  1591.     CloseLibrary(IntuitionBase);
  1592.     CloseLibrary(GfxBase);
  1593.  
  1594.         /* Return the special WBench signal. */
  1595.  
  1596.     FreeSignal(BenchSig);
  1597.  
  1598.         /* Sneak out before someone can
  1599.          * UnLoadSeg() us.
  1600.          */
  1601.  
  1602.     Forbid();
  1603.  
  1604.         /* Goodbye father. */
  1605.  
  1606.     if(DSeg -> Father)
  1607.         Signal(DSeg -> Father,SIGBREAKF_CTRL_D);
  1608.  
  1609.         /* Tricky, tricky, can we pull ourselves out of the
  1610.          * swamp? Has anybody tried this yet?
  1611.          */
  1612.  
  1613.     if(!DSeg -> Father)
  1614.     {
  1615.         register BPTR Segment = DSeg -> Segment;
  1616.  
  1617.         RemPort(&DSeg -> Port);
  1618.         FreeMem(DSeg -> Port . mp_Node . ln_Name,sizeof(PORTNAME));
  1619.  
  1620.         UnLoadSeg(Segment);
  1621.  
  1622.         Wait(NULL);
  1623.     }
  1624. }
  1625.  
  1626.     /* _main():
  1627.      *
  1628.      *    Modified Aztec C startup-routine, no CLI parsing,
  1629.      *    no Workbench parsing, absolutely nothing.
  1630.      */
  1631.  
  1632. long
  1633. _main()
  1634. {
  1635.     register ULONG SignalSet,MemSize,MaxSize;
  1636.     register short TextMode = 0;
  1637.  
  1638.     register struct Screen *Workbench;
  1639.     register long i;
  1640.  
  1641.     struct DateStamp Date;
  1642.  
  1643.     register struct Process *ThatsMe = (struct Process *)FindTask(NULL);
  1644.  
  1645.         /* If somebody called us from CLI... */
  1646.  
  1647.     if(ThatsMe -> pr_CLI)
  1648.         return(10);
  1649.  
  1650.         /* Is the DSeg structure anywhere? */
  1651.  
  1652.     if(!(DSeg = (struct DSeg *)FindPort(PORTNAME)))
  1653.         return(10);
  1654.  
  1655.         /* Check if it's below our current revision
  1656.          * number (probably doesn't support some
  1657.          * structure tags).
  1658.          */
  1659.  
  1660.     if(DSeg -> Revision < REVISION)
  1661.     {
  1662.         Signal(DSeg -> Father,DSeg -> RingBack);
  1663.  
  1664.         return(10);
  1665.     }
  1666.  
  1667.         /* Open those libraries. */
  1668.  
  1669.     if(!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0)))
  1670.     {
  1671.         Signal(DSeg -> Father,DSeg -> RingBack);
  1672.  
  1673.         return(20);
  1674.     }
  1675.  
  1676.     if(!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0)))
  1677.     {
  1678.         CloseLibrary(IntuitionBase);
  1679.         Signal(DSeg -> Father,DSeg -> RingBack);
  1680.  
  1681.         return(20);
  1682.     }
  1683.  
  1684.         /* Try to find the Workbench screen. */
  1685.  
  1686.     if(!(Workbench = (struct Screen *)FindTheBench()))
  1687.     {
  1688.         CloseLibrary(IntuitionBase);
  1689.         CloseLibrary(GfxBase);
  1690.         Signal(DSeg -> Father,DSeg -> RingBack);
  1691.  
  1692.         return(20);
  1693.     }
  1694.  
  1695.         /* Adjust the Window left offset. */
  1696.  
  1697.     LeftEdge = Workbench -> Width - 55 - Width;
  1698.  
  1699.         /* Open the backdrop window. */
  1700.  
  1701.     if(!(Window = (struct Window *)OpenWindow(&NewWindow)))
  1702.     {
  1703.         CloseLibrary(IntuitionBase);
  1704.         CloseLibrary(GfxBase);
  1705.         Signal(DSeg -> Father,DSeg -> RingBack);
  1706.  
  1707.         return(20);
  1708.     }
  1709.  
  1710.         /* Initialize the click sound data. */
  1711.  
  1712.     if(!InitSound())
  1713.     {
  1714.         FlushSound();
  1715.  
  1716.         CloseWindow(Window);
  1717.         CloseLibrary(IntuitionBase);
  1718.         CloseLibrary(GfxBase);
  1719.         Signal(DSeg -> Father,DSeg -> RingBack);
  1720.  
  1721.         return(20);
  1722.     }
  1723.  
  1724.         /* Install the handler code. */
  1725.  
  1726.     if(!InitHandler())
  1727.     {
  1728.         FlushHandler();
  1729.         FlushSound();
  1730.  
  1731.         CloseWindow(Window);
  1732.         CloseLibrary(IntuitionBase);
  1733.         CloseLibrary(GfxBase);
  1734.         Signal(DSeg -> Father,DSeg -> RingBack);
  1735.  
  1736.         return(20);
  1737.     }
  1738.  
  1739.     if((BenchSig = AllocSignal(-1)) == -1)
  1740.     {
  1741.         FlushHandler();
  1742.         FlushSound();
  1743.  
  1744.         CloseWindow(Window);
  1745.         CloseLibrary(IntuitionBase);
  1746.         CloseLibrary(GfxBase);
  1747.         Signal(DSeg -> Father,DSeg -> RingBack);
  1748.  
  1749.         return(20);
  1750.     }
  1751.  
  1752.         /* This passage initializes an invisible dummy
  1753.          * RastPort to be used for text/graphics rendering.
  1754.          */
  1755.  
  1756.     InitBitMap(&DummyMap,2,Width,Height);
  1757.  
  1758.         /* Clear the BitMap pointers. */
  1759.  
  1760.     for(i = 0 ; i < 8 ; i++)
  1761.         DummyMap . Planes[i] = NULL;
  1762.  
  1763.         /* Allocate the memory. */
  1764.  
  1765.     for(i = 0 ; i < 2 ; i++)
  1766.     {
  1767.         if(!(DummyMap . Planes[i] = AllocMem(Byte(Width) * 8,MEMF_CHIP)))
  1768.         {
  1769.             register long j;
  1770.  
  1771.             for(j = 0 ; j < 2 ; j++)
  1772.                 if(DummyMap . Planes[j])
  1773.                     FreeMem(DummyMap . Planes[j],Byte(Width) * 8);
  1774.  
  1775.             FlushHandler();
  1776.             FlushSound();
  1777.  
  1778.             CloseWindow(Window);
  1779.             CloseLibrary(IntuitionBase);
  1780.             CloseLibrary(GfxBase);
  1781.  
  1782.             FreeSignal(BenchSig);
  1783.  
  1784.             Signal(DSeg -> Father,DSeg -> RingBack);
  1785.  
  1786.             return(20);
  1787.         }
  1788.     }
  1789.  
  1790.         /* At last: mangle the RastPort. */
  1791.  
  1792.     InitRastPort(&DummyRPort);
  1793.  
  1794.     DummyRPort . BitMap = &DummyMap;
  1795.  
  1796.     RPort = &DummyRPort;
  1797.  
  1798.     SetRast(RPort,1);
  1799.  
  1800.         /* Fill the window and bring it to the front. */
  1801.  
  1802.     ShowTime();
  1803.  
  1804.         /* Patch system function. */
  1805.  
  1806.     Forbid();
  1807.     OldDisplayBeep = SetFunction(IntuitionBase,-0x60,NewDisplayBeep);
  1808.     OldCloseWBench = SetFunction(IntuitionBase,-0x4E,NewCloseWBench);
  1809.     Permit();
  1810.  
  1811.         /* Now we are truly running. */
  1812.  
  1813.     DSeg -> Child = (struct Task *)FindTask(NULL);
  1814.  
  1815.         /* How much memory is there around in this
  1816.          * Amiga?
  1817.          */
  1818.  
  1819.     MaxSize = MaxMemSize(MEMF_CHIP) + MaxMemSize(MEMF_FAST);
  1820.  
  1821.         /* Tell father to finish. */
  1822.  
  1823.     Signal(DSeg -> Father,DSeg -> RingBack);
  1824.  
  1825.     DSeg -> Father = NULL;
  1826.  
  1827.         /* Go into infinite loop waiting for signals. */
  1828.  
  1829.     FOREVER
  1830.     {
  1831.         SignalSet = Wait(SIG_TIMER | SIG_CLOSE | SIG_CLICK | SIG_TOGGL | SIG_BENCH | SIG_WINDO);
  1832.  
  1833.             /* Change the display mode? */
  1834.  
  1835.         if(SignalSet & SIG_TOGGL)
  1836.         {
  1837.             TextMode++;
  1838.  
  1839.             SetRast(RPort,1);
  1840.  
  1841.             if(TextMode == 3)
  1842.                 TextMode = 0;
  1843.         }
  1844.  
  1845.             /* Are we to click? */
  1846.  
  1847.         if((SignalSet & SIG_CLICK) && DSeg -> Click)
  1848.             Click();
  1849.  
  1850.             /* Are we to shut down? */
  1851.  
  1852.         if(SignalSet & SIG_CLOSE)
  1853.         {
  1854.             ShutDown();
  1855.             return(0);
  1856.         }
  1857.  
  1858.         if(SignalSet & SIG_BENCH)
  1859.         {
  1860.                 /* Close the window... */
  1861.  
  1862.             if(Window)
  1863.             {
  1864.                 CloseWindow(Window);
  1865.                 Window = NULL;
  1866.  
  1867.                 Delay(25);
  1868.  
  1869.                 FOREVER
  1870.                 {
  1871.                         /* Wait for wakeup-call... */
  1872.  
  1873.                     if((SetSignal(NULL,NULL) & SIG_CLOSE) == SIG_CLOSE)
  1874.                     {
  1875.                         SetSignal(NULL,SIG_CLOSE);
  1876.  
  1877.                         SignalSet = SIG_CLOSE;
  1878.                         break;
  1879.                     }
  1880.  
  1881.                     if(Workbench = (struct Screen *)FindTheBench())
  1882.                     {
  1883.                         SignalSet = NULL;
  1884.                         break;
  1885.                     }
  1886.  
  1887.                     Delay(25);
  1888.                 }
  1889.             }
  1890.  
  1891.                 /* Finish? */
  1892.  
  1893.             if(SignalSet & SIG_CLOSE)
  1894.             {
  1895.                 ShutDown();
  1896.                 return(0);
  1897.             }
  1898.  
  1899.                 /* Re-adjust the Window offset. */
  1900.  
  1901.             LeftEdge = Workbench -> Width - 55 - Width;
  1902.  
  1903.                 /* Open the window. */
  1904.  
  1905.             if(!(Window = (struct Window *)OpenWindow(&NewWindow)))
  1906.             {
  1907.                 ShutDown();
  1908.                 return(0);
  1909.             }
  1910.         }
  1911.  
  1912.             /* A window refresh call came in. */
  1913.  
  1914.         if(SignalSet & SIG_WINDO)
  1915.         {
  1916.             register struct IntuiMessage *IMsg;
  1917.  
  1918.                 /* Reply the Message (don't need it). */
  1919.  
  1920.             if(IMsg = (struct IntuiMessage *)GetMsg(Window -> UserPort))
  1921.                 ReplyMsg(IMsg);
  1922.         }
  1923.  
  1924.             /* Just a time check... */
  1925.  
  1926.         DateStamp(&Date);
  1927.  
  1928.             /* Ready to ring the bell? */
  1929.  
  1930.         if((Date . ds_Minute / 60 == DSeg -> AlarmHour) &&
  1931.            (Date . ds_Minute % 60 == DSeg -> AlarmMinute) &&
  1932.            (Date . ds_Tick / TICKS_PER_SECOND == DSeg -> AlarmSecond) &&
  1933.             DSeg -> Alarm)
  1934.             Ring();
  1935.  
  1936.             /* Show time and date. */
  1937.  
  1938.         if(TextMode == 0)
  1939.             ShowTime(TRUE);
  1940.         else
  1941.             ShowTime(FALSE);
  1942.  
  1943.             /* Show memory display. */
  1944.  
  1945.         if(TextMode == 1)
  1946.         {
  1947.             long BarLength;
  1948.  
  1949.                 /* For single bitplane Workbench
  1950.                  * screen -> use fill pattern.
  1951.                  */
  1952.  
  1953.             static USHORT Checkers[8]=
  1954.             {
  1955.                 0xAAAA,0x5555,
  1956.                 0xAAAA,0x5555,
  1957.                 0xAAAA,0x5555,
  1958.                 0xAAAA,0x5555
  1959.             };
  1960.  
  1961.                 /* How much memory is still available? */
  1962.  
  1963.             MemSize = AvailMem(MEMF_CHIP) + AvailMem(MEMF_FAST);
  1964.  
  1965.                 /* How long will the bar be? */
  1966.  
  1967.             BarLength = (152 * MemSize) / MaxSize;
  1968.  
  1969.             DrawImage(RPort,&ImageE,0,0);
  1970.  
  1971.                 /* Draw the full part. */
  1972.  
  1973.             if(Window -> RPort -> BitMap -> Depth < 2)
  1974.                 SetAfPt(RPort,&Checkers[0],1);
  1975.  
  1976.             SetAPen(RPort,3);
  1977.             RectFill(RPort,12,0,164 - BarLength,7);
  1978.  
  1979.             if(Window -> RPort -> BitMap -> Depth < 2)
  1980.                 SetAfPt(RPort,NULL,0);
  1981.  
  1982.                 /* Add the empty part. */
  1983.  
  1984.             SetAPen(RPort,2);
  1985.             RectFill(RPort,165 - BarLength,0,163,7);
  1986.         }
  1987.  
  1988.             /* Numeric memory display. */
  1989.  
  1990.         if(TextMode == 2)
  1991.         {
  1992.             UBYTE TempBuff[30];
  1993.  
  1994.             Format(TempBuff,"C: %07ld  F: %07ld",AvailMem(MEMF_CHIP),AvailMem(MEMF_FAST));
  1995.             PrintIt(TempBuff);
  1996.         }
  1997.  
  1998.             /* Transfer the image portion. */
  1999.  
  2000.         PickClip();
  2001.     }
  2002. }
  2003.